-3
I’m trying to create random numbers (01 to 60) with 6 digits
const valor = n => {
var add = 1, max = 12 - add;
if ( n > max ) {
return valor(max) + valor(n - max);
}
max = Math.pow(10, n+add);
var min = max/10;
var number = Math.floor( Math.random() * (max - min + 1) ) + min;
return ("" + number).substring(add);
}
I don’t know what to do there...
I tried to put the var number = Math.floor( Math.random() * 60 (max - min + 1) ) + min;
but makes a mistake...
Your code is generating a string with n random digits perfectly. I’m not sure what your goal is. " 6 digits" is the number of digits you can use to generate the number? If so, which digits can be used? If not, try to exclaim the question better.
– Marciel Leal
Random number is all right there , but I want example so when I put value(6) is random number with 6 digits right? ( 12, 92, 76, 65, 23, 99) but I don’t want to take the maximum of 60 and minimum 01 understood?
– Julio S
You want random numbers between 1 and 60, that’s it??
– Marciel Leal
Simm , not in a single number, is with 6... (0, 0, 0, 0, 0, 0)
– Julio S
Do you want 6 numbers from 1 to 60? Like: [12, 59, 41, 20, 30, 44]?
– Marciel Leal
Yeah, that’s what I want!
– Julio S
Just remembering that the answer below can generate repeated numbers (it was not clear if it could have repeated or not, but anyway, it is alert). If you want to ensure that there is no repetition, see here: https://answall.com/a/10284/112052
– hkotsubo