Skip to content

Instantly share code, notes, and snippets.

@vyasriday
Last active May 26, 2020 11:19
Show Gist options
  • Select an option

  • Save vyasriday/c31ba861e02c683ee7150d61c792691e to your computer and use it in GitHub Desktop.

Select an option

Save vyasriday/c31ba861e02c683ee7150d61c792691e to your computer and use it in GitHub Desktop.
Generating a random number in go using rand and time package
import  (
  "math/rand"
  "time"
)

func main() {
  // NewSource takes int64 value which is returned by time.Now().UnixNano()
  source := rand.NewSource(time.Now().UnixNano())
  r := rand.New(source)
  number :=r.Intn(100) // from 0 to 100 generate a random int number
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment