vendredi 18 août 2017

Why does golang repeats the same random number?

I'm new to golang and not sure why it prints the same number for rand.Intn(n int) int for every run:

package main

import (
    "fmt"
    "math/rand"
)


func main() {
    fmt.Println(rand.Intn(10)) 
}

The docs says :

Intn returns, as an int, a non-negative pseudo-random number in [0,n) from the default Source. It panics if n <= 0.

And how do I properly seed the random number generation?




Aucun commentaire:

Enregistrer un commentaire