Goで乱数

  • 30
    Like
  • 2
    Comment
More than 1 year has passed since last update.
rand.go
package main

import (
        "fmt"
        "math/rand"
        "time"
)

func main() {
        rand.Seed(time.Now().UnixNano())
        fmt.Println("random number is", rand.Intn(15))
}
$ go run rand.go
5
$ go run rand.go
12
$ go run rand.go
0
$