Skip to content

Instantly share code, notes, and snippets.

@imshvc
Last active September 14, 2024 09:08
Show Gist options
  • Save imshvc/1ea51576e398557c7c36a56ccb4b8652 to your computer and use it in GitHub Desktop.
Save imshvc/1ea51576e398557c7c36a56ccb4b8652 to your computer and use it in GitHub Desktop.
JavaScript pseudo-random number generator
/**
* 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