Last active
August 29, 2015 14:05
-
-
Save tadeubdev/f7b16de4a95204a5ebf1 to your computer and use it in GitHub Desktop.
Esta função retorna um número randomico com o tamanho requisitado
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
// 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