+ 2

How to generate non-repeating random numbers in javascript?

Generating non-repeating random numbers.

7th Nov 2017, 7:15 PM
Okonji Justin
Okonji Justin - avatar
3 Answers
+ 3
Store the random numbers in an array If the new random number is equal to any previous random number stored in the array, don't print it to the screen
8th Nov 2017, 6:01 AM
DAB
DAB - avatar
+ 1
I would advise not to store it in an array, but in an associative array that is done through an object. In this case, the verification of the presence of the computed number is made easier, without a cycle: by one operation in. https://code.sololearn.com/WaFH4sVitUf9
20th Dec 2017, 5:10 PM
Š’Š°Š“ŠøŠ¼ Š”ухŠ¾Ń‚ŠøŠ½ (Vadim Sukhotin)
Š’Š°Š“ŠøŠ¼ Š”ухŠ¾Ń‚ŠøŠ½ (Vadim Sukhotin) - avatar
+ 1
This works but it's a bit long šŸ˜… https://code.sololearn.com/WJ3O3UGPFzmG/?ref=app
4th Sep 2020, 2:37 PM
Philip
Philip - avatar