When C-sharp yield return and Random are used together, why do you get a variable that changes over time?

as shown in the figure, a function to get random numbers is written, and yield return

is used to save trouble.

:

:

if you write the code as

tbData.Text = String.Join("",data) + "\n\n" + String.Join("",data);
The data obtained from

is the same again, and the guess is related to time after several tests, because the seeds of random numbers vary according to time.
but why is this happening? Variables automatically change over time.

Mar.06,2021

because you use DateTime.Now.Millisecond as a random seed, this is millisecond. If two calls are less than 1 millisecond, the random seed you use twice is the same, and the result is the same. If the two calls are more than 1 millisecond, the seed is different and the random sequence is different.

Menu