Skip to content

Instantly share code, notes, and snippets.

@tadeubdev
Last active August 29, 2015 14:05
Show Gist options
  • Save tadeubdev/f7b16de4a95204a5ebf1 to your computer and use it in GitHub Desktop.
Save tadeubdev/f7b16de4a95204a5ebf1 to your computer and use it in GitHub Desktop.
Esta função retorna um número randomico com o tamanho requisitado
// Esta função retorna um número randomico com o tamanho requisitado
// `rep` deve ser um valor inteiro e deve ser no máximo 15
random = function ( rep )
{
if( 15 > rep )
{
alert( 'Oops! O número máximo é 15 !' );
rep = 15;
}
min = new Array( rep + 1 ).join( 1 );
max = new Array( rep + 1 ).join( 9 );
return Math.floor( Math.random() * ( max - min ) + min );
}
// Ex.:
alert( 'Endereço: Rua Tal, nº ' + random(3) );
alert( 'Seu código da promoção: ' + random(8) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment