Alex Rivera | Logout

Difficulty with Go Rand package

Asked 2011-11-27T20:13:01.363
19

Is there any Go function which returns true pseudo random number in every run? What I actually mean is, consider following code,

package main

import (
    "fmt"
    "rand"
)

func main() {
    fmt.Println(rand.Int31n(100))
}

Every time I execute this code, I get the same output. Is there a method that will return different, random results each time that it is called?

go
Edit
Report

1 Answer

0

rand.Seed(time.Now().UnixNano()) works on Ubuntu. I spent forever researching rand.Seed(time.Nanoseconds()). I finally found the Example: Google Search 2.1 on the golang tour.

answered 2012-08-01T19:46:53.253

Your Answer