Last active
September 14, 2024 09:08
-
-
Save imshvc/1ea51576e398557c7c36a56ccb4b8652 to your computer and use it in GitHub Desktop.
JavaScript pseudo-random number generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Pseudo-random number generator | |
* @author Nurudin Imsirovic <[email protected]> | |
* @param {number} count How many numbers to concatenate [1..10] | |
* @returns {number} | |
*/ | |
function rand(count = 10) { | |
count |= 0 | |
if (0 >= count) | |
count = 1 | |
if (count > 10) | |
count = 10 | |
let accum = '' | |
while (1) { | |
let num = Math.random() * 10 | 0 | |
if (0 >= num) | |
continue | |
accum += num | |
if (!--count) | |
break | |
} | |
return +accum | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment