V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
qianxi0410

go 中,`rand.Intn` 是否是线程安全的

  •  
  •   qianxi0410 ·
    qianxi0410 · May 24, 2022 · 2714 views
    This topic created in 1437 days ago, the information mentioned may be changed or developed.
    4 replies    2022-05-25 10:26:45 +08:00
    quella
        1
    quella  
       May 24, 2022
    https://pkg.go.dev/math/rand 这里有明确的提到
    qianxi0410
        2
    qianxi0410  
    OP
       May 24, 2022
    @quella 没太懂哎,如果只用 Seed 在 init 的时候进行一次初始化,可以看成是线程安全的吧。
    qianxi0410
        3
    qianxi0410  
    OP
       May 24, 2022
    ok ,大概知道了,默认源安全,新建源则不。Seed 初始化也是初始化默认源。
    liaohongxing
        4
    liaohongxing  
       May 25, 2022
    rand 这个包都不是安全的随机,就算线程安全也没意义 ,就算并发也是拿到同样值,
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2613 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 02:19 · PVG 10:19 · LAX 19:19 · JFK 22:19
    ♥ Do have faith in what you're doing.