mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-11 22:53:43 +08:00
rand 已经移到 math/rand下
This commit is contained in:
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user