从时间设置RNG种子

Setting the RNG seed from the time

当你打开一个新的 J 控制台并执行:

? 1000

您将始终看到相同的结果,689 (Try it online!)。

这是因为 RNG 总是以相同的初始种子开始。

我正在寻找一种半随机更改种子的方法。它不必是安全的(例如,使用毫秒级的时间或一些类似的方法就可以了)。

我假设我会使用 9!:45(在 this page 上记录)来执行此操作,但我不确定如何继续。

我也不关心我使用 4 个 RNG 中的哪一个。我只是想要一种即使在新控制台中也能产生不同随机结果的方法。

需要设置随机种子的国外是9!:1(Random Seed).

您可以使用 general/misc 插件中的 randomize 动词来使用 guids 随机设置随机种子,或者如果 guid 脚本不是当前时间可用的。例如:

   9!:0 ''            NB. Query the random seed/link
16807
   require 'numeric'
   randomize ''       NB. Set a new seed for the session
_1672920848 1179844600 923541917 _282857428
   9!:0 ''            NB. Query the random seed/link
_1672920848 1179844600 923541917 _282857428

randomize的定义是:

   randomize
3 : 0
 try.
   require 'guid'
   tmp=. _2 (3!:4) , guids 1
 catch.             NB. general/misc/guid.ijs not available
   tmp=. >:<.0.8*0 60 60 24 31#.0 0 0 0 _1+|.<.}.6!:0 ''
 end.
 ([ 9!:1) {.^:(2~:9!:42'') tmp    NB. set random initial random seed
)