Merge pull request #29 from showlovel/master

rand 已经移到 math/rand下
This commit is contained in:
Joe Chen
2013-11-17 21:46:36 -08:00

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())
}
}