Random numbers _ golang

Go's math/rand package provides pseudorandom number generation

package main

import (
    "fmt"
    "math/rand"
)

func main() {
    fmt.Print(rand.Intn(100), ",")
    fmt.Println()

    fmt.Println(rand.Float64())

    fmt.Println((rand.Float64()*5)+5, ",")

    s1 := rand.NewSource(42)
    r1 := rand.New(s1)

    fmt.Println(r1.Intn(100))

    s2 := rand.NewSource(42)
    r2 := rand.New(s2)
    fmt.Println(r2.Intn(100))
}
81,
0.9405090880450124
8.322800266092452 ,
5
5

总结 : 

  1 : ....

posted on 2015-03-26 13:25  xjk112  阅读(258)  评论(0编辑  收藏  举报