helloworld12
V2EX  ›  问与答

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

  •  
  •   helloworld12 · Aug 16, 2018 · 1700 views
    This topic created in 2838 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   ·   845 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 21:34 · PVG 05:34 · LAX 14:34 · JFK 17:34
    ♥ Do have faith in what you're doing.