亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
archive archive/tar archive/zip bufio bufio(緩存) builtin builtin(內(nèi)置包) bytes bytes(包字節(jié)) compress compress/bzip2(壓縮/bzip2) compress/flate(壓縮/flate) compress/gzip(壓縮/gzip) compress/lzw(壓縮/lzw) compress/zlib(壓縮/zlib) container container/heap(容器數(shù)據(jù)結(jié)構(gòu)heap) container/list(容器數(shù)據(jù)結(jié)構(gòu)list) container/ring(容器數(shù)據(jù)結(jié)構(gòu)ring) context context(上下文) crypto crypto(加密) crypto/aes(加密/aes) crypto/cipher(加密/cipher) crypto/des(加密/des) crypto/dsa(加密/dsa) crypto/ecdsa(加密/ecdsa) crypto/elliptic(加密/elliptic) crypto/hmac(加密/hmac) crypto/md5(加密/md5) crypto/rand(加密/rand) crypto/rc4(加密/rc4) crypto/rsa(加密/rsa) crypto/sha1(加密/sha1) crypto/sha256(加密/sha256) crypto/sha512(加密/sha512) crypto/subtle(加密/subtle) crypto/tls(加密/tls) crypto/x509(加密/x509) crypto/x509/pkix(加密/x509/pkix) database database/sql(數(shù)據(jù)庫/sql) database/sql/driver(數(shù)據(jù)庫/sql/driver) debug debug/dwarf(調(diào)試/dwarf) debug/elf(調(diào)試/elf) debug/gosym(調(diào)試/gosym) debug/macho(調(diào)試/macho) debug/pe(調(diào)試/pe) debug/plan9obj(調(diào)試/plan9obj) encoding encoding(編碼) encoding/ascii85(編碼/ascii85) encoding/asn1(編碼/asn1) encoding/base32(編碼/base32) encoding/base64(編碼/base64) encoding/binary(編碼/binary) encoding/csv(編碼/csv) encoding/gob(編碼/gob) encoding/hex(編碼/hex) encoding/json(編碼/json) encoding/pem(編碼/pem) encoding/xml(編碼/xml) errors errors(錯誤) expvar expvar flag flag(命令行參數(shù)解析flag包) fmt fmt go go/ast(抽象語法樹) go/build go/constant(常量) go/doc(文檔) go/format(格式) go/importer go/parser go/printer go/scanner(掃描儀) go/token(令牌) go/types(類型) hash hash(散列) hash/adler32 hash/crc32 hash/crc64 hash/fnv html html html/template(模板) image image(圖像) image/color(顏色) image/color/palette(調(diào)色板) image/draw(繪圖) image/gif image/jpeg image/png index index/suffixarray io io io/ioutil log log log/syslog(日志系統(tǒng)) math math math/big math/big math/bits math/bits math/cmplx math/cmplx math/rand math/rand mime mime mime/multipart(多部分) mime/quotedprintable net net net/http net/http net/http/cgi net/http/cookiejar net/http/fcgi net/http/httptest net/http/httptrace net/http/httputil net/http/internal net/http/pprof net/mail net/mail net/rpc net/rpc net/rpc/jsonrpc net/smtp net/smtp net/textproto net/textproto net/url net/url os os os/exec os/signal os/user path path path/filepath(文件路徑) plugin plugin(插件) reflect reflect(反射) regexp regexp(正則表達(dá)式) regexp/syntax runtime runtime(運(yùn)行時) runtime/debug(調(diào)試) runtime/internal/sys runtime/pprof runtime/race(競爭) runtime/trace(執(zhí)行追蹤器) sort sort(排序算法) strconv strconv(轉(zhuǎn)換) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系統(tǒng)調(diào)用) testing testing(測試) testing/iotest testing/quick text text/scanner(掃描文本) text/tabwriter text/template(定義模板) text/template/parse time time(時間戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
characters

  • import "math/rand"

  • 概觀

  • 索引

  • 示例

概觀

打包rand 執(zhí)行偽隨機(jī)數(shù)生成器。

隨機(jī)數(shù)由一個 Source 生成。頂級函數(shù)(如 Float64 和 Int )使用默認(rèn)的共享源,每次運(yùn)行程序時都會產(chǎn)生確定性的值序列。如果每次運(yùn)行都需要不同的行為,請使用 Seed 函數(shù)初始化默認(rèn) Source。默認(rèn)的 Source 對于多個 goroutine 并發(fā)使用是安全的,但由 NewSource 創(chuàng)建的源不是。

對于適合安全敏感工作的隨機(jī)數(shù)字,請參閱 crypto / rand 軟件包。

示例

package mainimport ("fmt""math/rand")func main() {
	rand.Seed(42) // Try changing this number!
	answers := []string{"It is certain","It is decidedly so","Without a doubt","Yes definitely","You may rely on it","As I see it yes","Most likely","Outlook good","Yes","Signs point to yes","Reply hazy try again","Ask again later","Better not tell you now","Cannot predict now","Concentrate and ask again","Don't count on it","My reply is no","My sources say no","Outlook not so good","Very doubtful",}
	fmt.Println("Magic 8-Ball says:", answers[rand.Intn(len(answers))])}

示例(Rand)

此示例顯示* Rand上每種方法的使用。全局功能的使用是一樣的,沒有接收器。

package mainimport ("fmt""math/rand""os""text/tabwriter")func main() {// Create and seed the generator.// Typically a non-fixed seed should be used, such as time.Now().UnixNano().// Using a fixed seed will produce the same output on every run.
	r := rand.New(rand.NewSource(99))// The tabwriter here helps us generate aligned output.
	w := tabwriter.NewWriter(os.Stdout, 1, 1, 1, ' ', 0)
	defer w.Flush()
	show := func(name string, v1, v2, v3 interface{}) {
		fmt.Fprintf(w, "%s\t%v\t%v\t%v\n", name, v1, v2, v3)}// Float32 and Float64 values are in [0, 1).show("Float32", r.Float32(), r.Float32(), r.Float32())show("Float64", r.Float64(), r.Float64(), r.Float64())// ExpFloat64 values have an average of 1 but decay exponentially.show("ExpFloat64", r.ExpFloat64(), r.ExpFloat64(), r.ExpFloat64())// NormFloat64 values have an average of 0 and a standard deviation of 1.show("NormFloat64", r.NormFloat64(), r.NormFloat64(), r.NormFloat64())// Int31, Int63, and Uint32 generate values of the given width.// The Int method (not shown) is like either Int31 or Int63// depending on the size of 'int'.show("Int31", r.Int31(), r.Int31(), r.Int31())show("Int63", r.Int63(), r.Int63(), r.Int63())show("Uint32", r.Uint32(), r.Uint32(), r.Uint32())// Intn, Int31n, and Int63n limit their output to be < n.// They do so more carefully than using r.Int()%n.show("Intn(10)", r.Intn(10), r.Intn(10), r.Intn(10))show("Int31n(10)", r.Int31n(10), r.Int31n(10), r.Int31n(10))show("Int63n(10)", r.Int63n(10), r.Int63n(10), r.Int63n(10))// Perm generates a random permutation of the numbers [0, n).show("Perm", r.Perm(5), r.Perm(5), r.Perm(5))}

索引

  • func ExpFloat64() float64

  • func Float32() float32

  • func Float64() float64

  • func Int() int

  • func Int31() int32

  • func Int31n(n int32) int32

  • func Int63() int64

  • func Int63n(n int64) int64

  • func Intn(n int) int

  • func NormFloat64() float64

  • func Perm(n int) []int

  • func Read(p []byte) (n int, err error)

  • func Seed(seed int64)

  • func Uint32() uint32

  • func Uint64() uint64

  • type Rand

  • func New(src Source) *Rand

  • func (r *Rand) ExpFloat64() float64

  • func (r *Rand) Float32() float32

  • func (r *Rand) Float64() float64

  • func (r *Rand) Int() int

  • func (r *Rand) Int31() int32

  • func (r *Rand) Int31n(n int32) int32

  • func (r *Rand) Int63() int64

  • func (r *Rand) Int63n(n int64) int64

  • func (r *Rand) Intn(n int) int

  • func (r *Rand) NormFloat64() float64

  • func (r *Rand) Perm(n int) []int

  • func (r *Rand) Read(p []byte) (n int, err error)

  • func (r *Rand) Seed(seed int64)

  • func (r *Rand) Uint32() uint32

  • func (r *Rand) Uint64() uint64

  • type Source

  • func NewSource(seed int64) Source

  • type Source64

  • type Zipf

  • func NewZipf(r *Rand, s float64, v float64, imax uint64) *Zipf

  • func (z *Zipf) Uint64() uint64

示例

Package Perm Package (Rand)

打包文件

exp.go normal.go rand.go rng.go zipf.go

func ExpFloat64

func ExpFloat64() float64

ExpFloat64 返回指數(shù)分布的 float64 ,其范圍為 (0, +math.MaxFloat64],其指數(shù)分布的速率參數(shù)(lambda)為1,平均值為默認(rèn) Source 的 1 / lambda(1)。不同的速率參數(shù),呼叫者可以使用以下方式調(diào)整輸出:

sample = ExpFloat64() / desiredRateParameter

func Float32

func Float32() float32

Float32 以默認(rèn) Source 的形式返回一個作為 float32 的 [0.0,1.0) 中的偽隨機(jī)數(shù)。

func Float64

func Float64() float64

Float64 以默認(rèn) Source 的形式返回,作為 float64,一個 [0.0,1.0) 中的偽隨機(jī)數(shù)字。

func Int

func Int() int

Int 從默認(rèn)的 Source 返回一個非負(fù)的偽隨機(jī) int。

func Int31

func Int31() int32

Int31 從默認(rèn) Source 返回一個非負(fù)的偽隨機(jī)31位整數(shù)作為 int32。

func Int31n

func Int31n(n int32) int32

Int31n 以默認(rèn) Source 的形式返回 [0,n)中的非負(fù)偽隨機(jī)數(shù),作為 int32。如果n <= 0,它會發(fā)生混亂。

func Int63

func Int63() int64

Int63 從默認(rèn)的 Source 返回一個非負(fù)的偽隨機(jī)的63位整數(shù)作為 int64。

func Int63n

func Int63n(n int64) int64

Int63n 以 int64 形式返回來自默認(rèn) Source 的 [0,n] 中的非負(fù)偽隨機(jī)數(shù)。如果n <= 0,它會發(fā)生混亂。

func Intn

func Intn(n int) int

Intn 以 int 形式返回來自默認(rèn) Source 的 [0,n] 中的非負(fù)偽隨機(jī)數(shù)。如果 n <= 0,它會發(fā)生混亂。

func NormFloat64

func NormFloat64() float64

NormFloat64 從默認(rèn)的 Source 返回正態(tài)分布的 float64,范圍為-math.MaxFloat64,+ math.MaxFloat64,標(biāo)準(zhǔn)正態(tài)分布(mean = 0,stddev = 1)。要產(chǎn)生不同的正態(tài)分布,調(diào)用者可以使用以下方式調(diào)整輸出:

sample = NormFloat64() * desiredStdDev + desiredMean

func Perm

func Perm(n int) []int

Perm 以默認(rèn) Source 的形式返回整數(shù) [0,n) 的偽隨機(jī)置換。

示例

package mainimport ("fmt""math/rand")func main() {for _, value := range rand.Perm(3) {
		fmt.Println(value)}}

func Read

func Read(p []byte) (n int, err error)

Read 從默認(rèn) Source 生成 len(p) 個隨機(jī)字節(jié),并將它們寫入 p。它總是返回 len(p) 和一個零錯誤。與 Rand.Read 方法不同,讀取對于并發(fā)使用是安全的。

func Seed

func Seed(seed int64)

Seed 使用提供的種子值將默認(rèn) Source 初始化為確定性狀態(tài)。如果種子沒有被調(diào)用,那么生成器的行為就像種子(1)播種一樣。具有相同余數(shù)的種子值除以2 ^ 31-1會生成相同的偽隨機(jī)序列。與 Rand.Seed 方法不同,種子對于并發(fā)使用是安全的。

func Uint32

func Uint32() uint32

Uint32從默認(rèn)的 Source 返回一個偽隨機(jī)的32位值作為 uint32。

func Uint64

func Uint64() uint64

Uint64 從默認(rèn)的 Source 返回一個偽隨機(jī)的64位值作為 uint64。

type Rand

Rand 是隨機(jī)數(shù)字的來源。

type Rand struct {        // contains filtered or unexported fields}

func New

func New(src Source) *Rand

New 返回一個新的Rand,它使用 src 中的隨機(jī)值生成其他隨機(jī)值。

func (*Rand) ExpFloat64

func (r *Rand) ExpFloat64() float64

ExpFloat64 返回指數(shù)分布的 float64,其范圍為 (0, +math.MaxFloat64] ,其指數(shù)分布的速率參數(shù)(lambda)為1,平均值為 1 / lambda(1)。為了生成具有不同速率參數(shù)的分布,呼叫者可以使用以下方式調(diào)整輸出:

sample = ExpFloat64() / desiredRateParameter

func (*Rand) Float32

func (r *Rand) Float32() float32

Float32 作為 float32 返回 [0.0,1.0) 中的偽隨機(jī)數(shù)。

func (*Rand) Float64

func (r *Rand) Float64() float64

Float64 作為 float64 返回 [0.0,1.0) 中的偽隨機(jī)數(shù)。

func (*Rand) Int

func (r *Rand) Int() int

Int 返回一個非負(fù)的偽隨機(jī) int。

func (*Rand) Int31

func (r *Rand) Int31() int32

Int31 以 int32 形式返回一個非負(fù)的偽隨機(jī)31位整數(shù)。

func (*Rand) Int31n

func (r *Rand) Int31n(n int32) int32

Int31n 以 int32 形式返回 [0,n)中的非負(fù)偽隨機(jī)數(shù)。如果 n <= 0,它會發(fā)生混亂。

func (*Rand) Int63

func (r *Rand) Int63() int64

Int63 以 int64 的形式返回一個非負(fù)的偽隨機(jī)63位整數(shù)。

func (*Rand) Int63n

func (r *Rand) Int63n(n int64) int64

Int63n 以 int64 的形式返回 [0,n)中的非負(fù)偽隨機(jī)數(shù)。如果 n <= 0,它會發(fā)生混亂。

func (*Rand) Intn

func (r *Rand) Intn(n int) int

Intn 返回 int [0,n] 中的非負(fù)偽隨機(jī)數(shù)。如果 n <= 0,它會發(fā)生混亂。

func (*Rand) NormFloat64

func (r *Rand) NormFloat64() float64

NormFloat64 返回正態(tài)分布的 float64,范圍為-math.MaxFloat64,+ math.MaxFloat64,標(biāo)準(zhǔn)正態(tài)分布(mean = 0,stddev = 1)。要產(chǎn)生不同的正態(tài)分布,呼叫者可以使用以下方式調(diào)整輸出:

sample = NormFloat64() * desiredStdDev + desiredMean

func (*Rand) Perm

func (r *Rand) Perm(n int) []int

Perm作為一個 n 分片返回一個整數(shù) [0,n)的偽隨機(jī)置換。

func (*Rand) Read

func (r *Rand) Read(p []byte) (n int, err error)

Read 生成 len(p)個隨機(jī)字節(jié)并將它們寫入p。它總是返回 len(p)和一個零錯誤。閱讀不應(yīng)與任何其他 Rand 方法同時調(diào)用。

func (*Rand) Seed

func (r *Rand) Seed(seed int64)

Seed 使用提供的種子值將發(fā)生器初始化為確定性狀態(tài)。Seed 不應(yīng)該與任何其他 Rand 方法同時調(diào)用。

func (*Rand) Uint32

func (r *Rand) Uint32() uint32

Uint32 返回一個偽隨機(jī)的32位值作為 uint32。

func (*Rand) Uint64

func (r *Rand) Uint64() uint64

Uint64 返回一個偽隨機(jī)的64位值作為 uint64。

type Source

源表示均勻分布的偽隨機(jī) int64 值的來源,范圍 [0,1 << 63)。

type Source interface {        Int63() int64        Seed(seed int64)}

func NewSource

func NewSource(seed int64) Source

NewSource 返回一個新的偽隨機(jī)源,并給定值。與頂級函數(shù)使用的默認(rèn)源不同,此源對于多個 goroutine 并發(fā)使用并不安全。

type Source64

Source64是一個Source,它也可以直接在[0,1 << 64)范圍內(nèi)生成均勻分布的偽隨機(jī)uint64值。如果 Rand r 的底層 Source 實(shí)現(xiàn)Source64,則 r.Uint64 將一次調(diào)用的結(jié)果返回給 s.Uint64,而不是對 s.Int63進(jìn)行兩次調(diào)用。

type Source64 interface {
        Source        Uint64() uint64}

type Zipf

Zipf 生成 Zipf 分布式變量。

type Zipf struct {        // contains filtered or unexported fields}

func NewZipf

func NewZipf(r *Rand, s float64, v float64, imax uint64) *Zipf

NewZipf 返回一個 Zipf 變量生成器。生成器生成值 k∈0,imax,使得P(k)與(v + k)**(-s)成比例。要求:s> 1且v> = 1。

func (*Zipf) Uint64

func (z *Zipf) Uint64() uint64

Uint64 返回從 Zipf 對象描述的 Zipf 分布中繪制的值。

Previous article: Next article: