Last active
September 4, 2019 22:42
-
-
Save suissa/06100cd6fb96cbeeb76cd098e2957796 to your computer and use it in GitHub Desktop.
Gerador de sequência de números aleatórios corrigida
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
const getRandomNumber = ( size = 4 ) => | |
Math.floor( | |
Math.random() * ( Number( `1e${size}` ) ) | |
); | |
const getRandomNumberSequence = ( size = 4 ) => { | |
const n = getRandomNumber(size); | |
return (String(n).length === size) ? n : `0${n}`; | |
}; | |
/* | |
DEFAULT 4: 8615 | |
DEFAULT 4: 0355 | |
DEFAULT 4: 5302 | |
DEFAULT 4: 0504 | |
DEFAULT 4: 7325 | |
DEFAULT 4: 5204 | |
DEFAULT 4: 7264 | |
DEFAULT 4: 2660 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment