rand 已经移到 math/rand下

This commit is contained in:
showlovel
2013-11-18 10:25:03 +08:00
parent 26e8fd1165
commit 8247b1c01c

View File

@@ -348,25 +348,25 @@ Example 4.10 [random.go](examples/chapter_4/random.go) 演示了如何生成 10
package main
import (
fmt
rand
time
"fmt"
"math/rand"
"time"
)
func main() {
for i := 0; i < 10; i++ {
a := rand.Int()
fmt.Printf(%d / , a)
fmt.Printf("%d / ", a)
}
for i := 0; i < 5; i++ {
r := rand.Intn(8)
fmt.Printf(%d / , r)
fmt.Printf("%d / ", r)
}
fmt.Println()
timens := int64(time.Now().Nanosecond())
rand.Seed(timens)
for i := 0; i < 10; i++ {
fmt.Printf(%2.2f / , 100*rand.Float32())
fmt.Printf("%2.2f / ", 100*rand.Float32())
}
}