Multiple random values in one frame

Hi guys,

Does anyone happen to know how exactly this works on the background and if it is ok to do:

float one;
float two;
float three;
float four;
float five;

    void Update()
    {
        one = Random.value;
        two = Random.value;
        three = Random.value;
        four = Random.value;
        five = Random.value;
    }

I need to random bunch of variables in one single frame. When I do it like above and print them, they all seem to random different values and all seems ok.
But I heard that since the Random is depended on the clock, randoming in one frame may produce same results… This doesn’t happen in my test but I would still like to verify if it’s ok to leave the code like this.

If this is fine, then what’s the rumor about randoming multiple times in one frame?

Thanks!

When first requesting a random value, the Random class creates a new random number generator. This generator needs a seed which is used to generate the first random value. If one is not provided, the current time in milliseconds is used. All subsequent values are are used to generate the number after it. This means generating several random numbers in the same frame is perfectly fine.


Unity blog has an excellent post about random numbers.