V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
helloworld12
V2EX  ›  问与答

golang 中, 在确定随机种子的情况下,如何获取指定位置的随机数

  •  
  •   helloworld12 · Aug 16, 2018 · 1667 views
    This topic created in 2823 days ago, the information mentioned may be changed or developed.

    看到有文章说,随机种子确定, 随机算法确定,就可以确定随机序列

    那么 golang 里面怎么获取这个序列, 以及指定 index 的随机数 ?

    src := rand.NewSource(1000)
    sand := rand.New(src)
    itemI := sand.GetItemAt(index)      // GetItemAt 的方法是什么,查了 api 好像都不是
    

    嗯, 谢谢

    2 replies    2018-09-16 22:50:08 +08:00
    aliipay
        1
    aliipay  
       Sep 15, 2018   ❤️ 1
    随机数序列是确定的,循环获取随机就得到序列了。
    没有 GetItemAt 这个 api,因为这么做没任何意义。
    helloworld12
        2
    helloworld12  
    OP
       Sep 16, 2018
    嗯 谢谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3038 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 13:35 · PVG 21:35 · LAX 06:35 · JFK 09:35
    ♥ Do have faith in what you're doing.