0

How to store random number in a 2D arrays without repeating any number

Program

26th Dec 2019, 3:44 PM
deepak
deepak - avatar
2 Réponses
+ 2
If the chance of getting same number is big, and if there is a specified range for the numbers, I think one good way could be: NUMBERS: numbers in array MIN: minimum number MAX: maximum number Check whether NUMBERS > MAX - MIN. Take a random number between MIN and MAX. While the number is in the array, add 1 to the number. When number > MAX, set it MIN. When the number is not in the array, put it there and stop incrementing it by 1.
26th Dec 2019, 4:15 PM
Seb TheS
Seb TheS - avatar
+ 1
You would generate a random number, and if it is in the array, generate another one and see if it’s in the array.
26th Dec 2019, 3:59 PM
Jax
Jax - avatar