+ 6
Can random number generator generates a same number continually multiple times?
I am making a game. And in that game I need a loop that will run until rng (random number generator) returns a number that does not match the elements of the array. But one question is bothering me that if rng returns the same number many times? Then my loop will go on for a long time. And there will be a bug in my game. Because no one knows when rng throws what number at you.
3 Respuestas
+ 7
Commander Erwin Smith ,
> can you please give a sample what range of numers you are using? (e.g. 100 upto 300, 10 numbers required)
> using random.sample() is giving unique numbers.
> you could also use a list that stores the already used numbers. each time the rng gives you a number, you can check if this number was already used. in this case rng has to generate a new number.
+ 4
Depends on seed value.
Random seed place a role in generating true random numbers..
https://stackoverflow.com/questions/14914595/what-is-a-seed-in-terms-of-generating-a-random-number
https://www.geeksforgeeks.org/random-seed-in-JUMP_LINK__&&__python__&&__JUMP_LINK/amp/
+ 3
If you want to avoid repetition, maybe just create a sequence of all possible values, and sort them in random order. This is also called a "shuffle" algorithm and many languages have built-in functions to randomize a list or array this way. Then you can take as many values from the shuffled list (don't need to use all) and each of them will be unique.