01-11-2020 03:34
01-11-2020 03:34
How can I make Math.random() not always generate same numbers when starting an app in the simulator?
Answered! Go to the Best Answer.
01-15-2020 00:57 - edited 01-15-2020 01:02
01-15-2020 00:57 - edited 01-15-2020 01:02
Yes
Got random to work by making a loop millisecond, of current time, number of times to generate different amount of random number each time the simulator starts, instead of always getting the identical range So did not need to write my own new random function.
Like:
let timer = new Date().getMilliseconds();
let total = 0
console.log("timer:" + timer);
for (; timer > 0; timer--) {
total += Math.random();
}
console.log("timer:" + timer + ", total: " + total);
BTW I had to use the random generated number else the build would see it was not used and not do it.
Hence this did not work:
for (; timer > 0; timer--) {
Math.random();
}
01-15-2020 00:57 - edited 01-15-2020 01:02
01-15-2020 00:57 - edited 01-15-2020 01:02
Yes
Got random to work by making a loop millisecond, of current time, number of times to generate different amount of random number each time the simulator starts, instead of always getting the identical range So did not need to write my own new random function.
Like:
let timer = new Date().getMilliseconds();
let total = 0
console.log("timer:" + timer);
for (; timer > 0; timer--) {
total += Math.random();
}
console.log("timer:" + timer + ", total: " + total);
BTW I had to use the random generated number else the build would see it was not used and not do it.
Hence this did not work:
for (; timer > 0; timer--) {
Math.random();
}
01-15-2020 01:17
01-15-2020 01:17
Thanks for posting this. We have a ticket for the issue.