helloworld12
V2EX  ›  问与答

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

  •  
  •   helloworld12 · Aug 16, 2018 · 2002 views
    This topic created in 3007 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
    aliipay
    Sep 15, 2018❤️1
    1
    随机数序列是确定的,循环获取随机就得到序列了。
    没有 GetItemAt 这个 api,因为这么做没任何意义。
    helloworld12
    helloworld12
    OP
    Sep 16, 2018
    2
    嗯 谢谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4152 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 01:56 · PVG 09:56 · LAX 17:56 · JFK 20:56
    ♥ Do have faith in what you're doing.