Generating identical random numbers in sequence after time seed? (Running on my machine)

后端 未结 2 437
既然无缘
既然无缘 2021-01-23 01:07

I\'m trying to understand precisely why, when called from an external function, my time seeded random number generator returns sequences of identical numbers.

Minimal wo

2条回答
  •  遇见更好的自我
    2021-01-23 01:27

    I'm not a Go expert but I think the problem is a generic programming issue. It is related to the fact you set the seed to each call. The seed is based on time function. So what is happening is that in a very short time, you have a number of calls while the time is not changed (yet) and so you get the same value because you are setting the same seed again and again.

    Try to set the seed, once only and outside the for loop of calls.

提交回复
热议问题