0
How can I generate random numbers without repeating them?
I want to generate random numbers between 1 and 100, but I want the generated number to be different from all the previous generated numbers. How can I do it? Help me please
4 ответов
+ 3
you can take one array and put randomize number you get. Now when you get next number you can first check to the array if it is already present then neglect that and get new random number. follow same thing up to array size will become 100.
+ 3
nums.indexOf(num)!=-1 // is to make sure the random number is not repected in the array
nums.push(num) // is to update the array with the random number num
0
thanks guys :D