The following code:
func main() {
rand.Seed(time.Now().UnixNano())
count := 0
for i := 0; i < 100; i++{
if(rand.Float32() < 0.5){
fmt.Println("1")
count++
}else{
fmt.Println("0")
}
}
fmt.Println(count)
}
always produces the same exact pattern of 1s and 0s. I assumed seeding based on time at the beginning of the block would yield different results on each run. What am I missing?
Aucun commentaire:
Enregistrer un commentaire