幸运飞艇停吗

ASP源碼.NET源碼PHP源碼JSP源碼JAVA源碼DELPHI源碼PB源碼VC源碼VB源碼Android源碼
當前位置:首頁 >> 網頁制作 >> web前端 >> 關于golang隨機數的一個好玩的事情

關于golang隨機數的一個好玩的事情

來源:網絡整理     時間:2019-07-02     關鍵詞:

BENPIANWENZHANGZHUYAOJIESHAOLE" GUANYUgolangSUIJISHUDEYIGEHAOWANDESHIQING",ZHUYAOSHEJIDAOFANGMIANDENEIRONG,DUIYUwebQIANDUANGANXINGQUDETONGXUEKEYICANKAOYIXIA: golangSUIJISHUYOUYIGEHENHAOWANDEDIFANG,RUGUOWOMENBUZIXINGDINGYISUIJISHUZHONGZIDEHUA,MEICIDESUIJISHUDOUSHIYIYANGDE。BIRUWOMENforXUNHUAN,QU8GESUIJISHU,MEICIYUNXINGJIEGUOSHIYIMOYIYANGDE。DAIMA...

golangSUIJISHUYOUYIGEHENHAOWANDEDIFANG,RUGUOWOMENBUZIXINGDINGYISUIJISHUZHONGZIDEHUA,MEICIDESUIJISHUDOUSHIYIYANGDE。


BIRUWOMENforXUNHUAN,QU8GESUIJISHU,MEICIYUNXINGJIEGUOSHIYIMOYIYANGDE。DAIMARUXIA:




package main


import (

    "fmt"

幸运飞艇停吗    "math/rand"

)


幸运飞艇停吗var c chan int


func product(){

幸运飞艇停吗    r := rand.Intn(10)

幸运飞艇停吗    fmt.Println("SUIJISHU: ", r)

    c <- r

}


func main(){

    c = make(chan int, 8)

    for i:= 0; i<8; i++{

        go product()

    }

幸运飞艇停吗    total := 0

幸运飞艇停吗    for i:= 0; i<8; i++{

        total += <- c

幸运飞艇停吗    }

    fmt.Println("ZONGHE: ", total)

}




JIEGUORUXIA:



?  src go run index.go

SUIJISHU:  9

SUIJISHU:  7

SUIJISHU:  7

幸运飞艇停吗SUIJISHU:  1

幸运飞艇停吗SUIJISHU:  8

SUIJISHU:  5

SUIJISHU:  1

SUIJISHU:  0

幸运飞艇停吗ZONGHE:  38

幸运飞艇停吗?  src go run index.go

SUIJISHU:  7

SUIJISHU:  8

幸运飞艇停吗SUIJISHU:  5

SUIJISHU:  1

幸运飞艇停吗SUIJISHU:  0

SUIJISHU:  1

SUIJISHU:  9

SUIJISHU:  7

ZONGHE:  38

?  src go run index.go

SUIJISHU:  1

幸运飞艇停吗SUIJISHU:  8

SUIJISHU:  1

幸运飞艇停吗SUIJISHU:  5

幸运飞艇停吗SUIJISHU:  7

幸运飞艇停吗SUIJISHU:  0

SUIJISHU:  7

幸运飞艇停吗SUIJISHU:  9

ZONGHE:  38

?  src go run index.go

幸运飞艇停吗SUIJISHU:  7

SUIJISHU:  1

SUIJISHU:  9

幸运飞艇停吗SUIJISHU:  1

幸运飞艇停吗SUIJISHU:  8

SUIJISHU:  5

SUIJISHU:  0

SUIJISHU:  7

幸运飞艇停吗ZONGHE:  38

?  src go run index.go

幸运飞艇停吗SUIJISHU:  7

SUIJISHU:  9

SUIJISHU:  1

SUIJISHU:  8

幸运飞艇停吗SUIJISHU:  0

SUIJISHU:  5

SUIJISHU:  1

幸运飞艇停吗SUIJISHU:  7

ZONGHE:  38

?  src go run index.go

SUIJISHU:  7

幸运飞艇停吗SUIJISHU:  1

幸运飞艇停吗SUIJISHU:  1

幸运飞艇停吗SUIJISHU:  9

SUIJISHU:  8

幸运飞艇停吗SUIJISHU:  5

SUIJISHU:  0

SUIJISHU:  7

ZONGHE:  38




KEYIKANCHU,MEICISUIJISHUDOUSHI0、1、1、5、7、7、8、9,ZONGHEYIZHIDOUSHI38。YINWEISHIYONGLEgoGUANJIANZI,SUOYISHUNXUBUTONG,DANSHIRUGUOQUDIAOgoGUANJIANZI,GAIWEIDANQUCHENGDEHUA,NEIZHENJIUSHISHUNXUHEZHIDOUWANQUANYIMOYIYANGLE。


WEISHENME?


WOMENDAKAIgolangDEYUANMA,KEYIKANDAO:




幸运飞艇停吗rand.Int()SHIJISHIfunc Int() int { return globalRand.Int() }

幸运飞艇停吗ERglobalRandSHIvar globalRand = New(&lockedSource{src: NewSource(1)})

NewSourceYOUSHI

幸运飞艇停吗func NewSource(seed int64) Source {

    var rng rngSource rng.Seed(seed) 

幸运飞艇停吗    return &rng 

}




幸运飞艇停吗YEJIUSHISHUO,MEICIZAIMORENSUIJIDESHIHOU,golangSHIGUDINGLEYISHUZI1ZUOWEIZHONGZI,JINXINGSUIJI。NEIZHONGZIDOUGUDINGLEDEHUA,MEICIZHIXINGDESHIHOUJIEGUODANGRANSHIYIYANGDELE。


ERYAOJIEJUEZHEGEWENTI,JIUXUYAOYISHIJIANZUOWEISUIJISHUZHONGZI。DAIMARUXIA:




package main


import (

    "fmt"

幸运飞艇停吗    "math/rand"

    "time"

)


幸运飞艇停吗var c chan int


func product(){

幸运飞艇停吗    rand.Seed(int64(time.Now().Nanosecond()))

    r := rand.Intn(10)

    fmt.Println("SUIJISHU: ", r)

    c <- r

}


func main(){

幸运飞艇停吗    c = make(chan int, 8)

    for i:= 0; i<8; i++{

        go product()

    }

    total := 0

    for i:= 0; i<8; i++{

        total += <- c

幸运飞艇停吗    }

    fmt.Println("ZONGHE: ", total)

}




ZHESHIZAIYUNXING,JIUHUIFAXIANBIJIAO“SUIJI”LE。




?  src go run index.go

幸运飞艇停吗SUIJISHU:  8

SUIJISHU:  1

幸运飞艇停吗SUIJISHU:  3

SUIJISHU:  9

幸运飞艇停吗SUIJISHU:  6

幸运飞艇停吗SUIJISHU:  8

幸运飞艇停吗SUIJISHU:  5

SUIJISHU:  7

ZONGHE:  47

?  src go run index.go

SUIJISHU:  0

SUIJISHU:  5

幸运飞艇停吗SUIJISHU:  1

幸运飞艇停吗SUIJISHU:  3

SUIJISHU:  2

SUIJISHU:  3

SUIJISHU:  5

SUIJISHU:  1

幸运飞艇停吗ZONGHE:  20

?  src go run index.go

SUIJISHU:  2

SUIJISHU:  9

幸运飞艇停吗SUIJISHU:  8

SUIJISHU:  2

SUIJISHU:  5

幸运飞艇停吗SUIJISHU:  1

SUIJISHU:  9

SUIJISHU:  0

幸运飞艇停吗ZONGHE:  36

幸运飞艇停吗?  src go run index.go

SUIJISHU:  4

SUIJISHU:  1

SUIJISHU:  0

SUIJISHU:  4

幸运飞艇停吗SUIJISHU:  6

SUIJISHU:  2

幸运飞艇停吗SUIJISHU:  8

幸运飞艇停吗SUIJISHU:  8

幸运飞艇停吗ZONGHE:  33

幸运飞艇停吗?  src go run index.go

幸运飞艇停吗SUIJISHU:  0

SUIJISHU:  3

SUIJISHU:  5

幸运飞艇停吗SUIJISHU:  1

SUIJISHU:  1

幸运飞艇停吗SUIJISHU:  6

SUIJISHU:  5

幸运飞艇停吗SUIJISHU:  6

幸运飞艇停吗ZONGHE:  27




ERPHPZUOWEIZUIHAODEYUYAN,ZHEDIANHUANSHIBIJIAORENXINGHUADE,PHPMORENJIUSHIYISHIJIANZUOWEIZHONGZIDE。ZAIWENDANGZHONGYOUZHEMEYIJUHUA:



Note: ZI PHP 4.2.0 QI,BUZAIXUYAOYONG srand() HUO mt_srand() GEISUIJISHUFASHENGQIBOZHONG ,YINWEIXIANZAISHIYOUXITONGZIDONGWANCHENGDE。

幸运飞艇停吗 YISHANGJIUJIESHAOLE GUANYUgolangSUIJISHUDEYIGEHAOWANDESHIQING,BAOKUOLEFANGMIANDENEIRONG,XIWANGDUIwebQIANDUANYOUXINGQUDEPENGYOUYOUSUOBANGZHU。

幸运飞艇停吗 BENWENWANGZHILIANJIE:http://snifly.cn/article/detail_4596425.html

幸运飞艇停吗

上一篇Eclipse Memory Analyzer toolMAT使用詳細說明 下一篇:沒有了

相關圖片

相關文章