Skip to content

Instantly share code, notes, and snippets.

@suissa
Created September 4, 2019 23:27
Show Gist options
  • Save suissa/1453989384a83490c9f733a342b7f9b0 to your computer and use it in GitHub Desktop.
Save suissa/1453989384a83490c9f733a342b7f9b0 to your computer and use it in GitHub Desktop.
const getRandomNumber = ( size = 4 ) =>
Math.floor(
Math.random() * ( Number( `1e${size}` ) )
);
const getPlateNumbers = (n) => Array(4 - n.length).fill('0').join('') + n;
const getRandomNumberSequence = ( size = 4 ) => {
const n = String(getRandomNumber(size));
return `${(n.length) < 4 ? getPlateNumbers(n) : n}`;
};
console.log(
'De 100 tentativas as seguintes são menores de 0.1: ')
for(let c = 0; c < 100; c++) {
const n = getRandomNumberSequence()
if (n.startsWith('0')) console.log(n)
}
console.log(
'De 100 tentativas as seguintes são menores de 0.01: ')
for(let c = 0; c < 100; c++) {
const n = getRandomNumberSequence()
if (n.startsWith('00')) console.log(n)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment