Skip to content

Instantly share code, notes, and snippets.

@Jason-cqtan
Last active October 17, 2019 09:49
Show Gist options
  • Save Jason-cqtan/59b32931b84cbe23f44b5f96c9affbd2 to your computer and use it in GitHub Desktop.
Save Jason-cqtan/59b32931b84cbe23f44b5f96c9affbd2 to your computer and use it in GitHub Desktop.
生成随机数
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
for i := 0; i < 10; i++ {
a := rand.Int()
fmt.Printf("%d / ", a)
}
fmt.Println()
for i := 0; i < 5; i++ {
r := rand.Intn(8)
fmt.Printf("%d / ", r)
}
fmt.Println()
timens := int64(time.Now().Nanosecond())
fmt.Println(timens)
rand.Seed(timens)
for i := 0; i < 10; i++ {
fmt.Printf("%2.2f / ", 100*rand.Float32())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment