This question has already been answered:

The rand.Int() function produces the same number each time. I thought that I had something with the machine, but no, Go playground also gives out one number. How to get a random (so that with each call was a new number)?

Reported as a duplicate member of the Spirit Community ♦ Jul 9 '17 at 8:39 pm .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • no, it gives out different numbers in successive calls - Abyx

1 answer 1

math/rand is a pseudo-random number modulus. If you want a different result each time, then either use a different initial value (for example, the current time):

 rand.Seed(time.Now().UnixNano()) 

Or, if you need crypt-proof random data, use crypto/rand .

In addition, it is worth remembering that the time on the Go Playground always begins at the same moment.