Skip to content

Instantly share code, notes, and snippets.

@suissa
Last active September 4, 2019 22:42
Show Gist options
  • Save suissa/06100cd6fb96cbeeb76cd098e2957796 to your computer and use it in GitHub Desktop.
Save suissa/06100cd6fb96cbeeb76cd098e2957796 to your computer and use it in GitHub Desktop.
Gerador de sequência de números aleatórios corrigida
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