Random.Range? Riiight

I use the following code to generate a random number:

Random.seed = 5;
float RandomNum = Random.Range(2.4f,18.4f);

This produces one result of 18.37, and then an infinite amount of 8.27 results. I tried setting the seed to a random number (Random.seed = Random.Range(1,100)) every time it generates, but this only makes observable number patterns, like 4 numbers that are repeated exactly over and over again in the same order. Its not truly random. Am I doing something wrong?

I assume you’re setting the seed every time before you call Random.Range()?

The seed should only be set once. In fact you don’t have to set it at all unless you need to reproduce the same sequence of pseudo-random numbers several times.

Thanks! It seems I had a misunderstanding of what the Random.seed method does. Just to clarify, if I call Random.seed = 5, I will get the same sequence afterward through a series of Random.Range calls?

Yep. 8)

Yes.

Random in any program is never truly random. Computer generated randoms are always called Pseudorandom because they follow consistent patterns.

Check Periodicity for a little info on seed values, although I’m not actually sure which method Unity uses.

Yes I am aware that its not truly random. I just didn’t realize I was scrambling the process by resetting the seed over and over again. :smile: