使用桃子时随机状态如何传播到不同的线程?

How does the random state propagate to different threads when using peach?

我试图了解在使用 peach 时随机状态如何传播到线程,但找不到太多关于它的文档。

根据经验,从下面的测试来看,似乎线程最终会产生不同的种子,但这些种子可能与主节点的随机种子无关。

q) \S 123 
q) {[x] show 20?10} peach til 10
5 1 5 7 4 4 2 2 4 9 0 7 6 4 5 2 1 7 1 9
0 3 9 6 4 3 6 0 9 1 6 7 4 4 0 0 7 0 8 4
5 7 9 4 6 8 8 6 4 6 4 7 7 6 8 9 8 7 4 2
2 8 4 2 3 2 0 3 6 3 1 2 7 8 8 3 9 2 7 6
1 0 3 9 5 2 7 5 5 3 1 2 6 1 8 9 5 2 5 5
2 6 6 7 2 0 6 9 1 4 7 9 9 8 2 7 1 4 4 3
3 2 2 0 0 9 2 6 3 1 6 1 6 5 3 4 6 0 8 9
2 3 0 3 4 3 9 0 8 1 5 7 1 1 3 3 0 5 3 4
0 9 5 2 1 2 0 2 6 4 5 7 9 7 2 6 9 1 9 8
5 7 8 0 5 6 0 2 0 0 0 5 6 4 4 8 3 9 9 2

但是 运行 这两行第二次都没有重现这个答案。

所以我的问题是:

  1. 线程的seed和master的随机状态有关系吗?
  2. 我们能保证在每个线程获得不同的种子吗?
  3. 关于在每个线程设置种子的最佳实践或其他获得可重现结果的方法有什么建议吗?

谢谢

并非总是如此,它已在 v3.1 中修复

q).z.K
3f
q)count distinct {10?10}peach til 1000
931

q).z.K
4f
q)count distinct {10?10}peach til 1000
1000

来自发行说明

2013.08.19
FIX
the random number generator was not thread-safe. Now the behaviour is as follows
 rng is thread local.
 \S 1234 sets the seed for the rng for the main thread only.
 the rng in a slave thread is assigned a seed based on the slave thread number.
 in multithreaded input mode, the seed is based on socket descriptor.
 instances started on ports 20000 thru 20099 (slave procs, used with e.g. q -s -4) have the main thread's default seed based on the port number.
q)\s
-2i
q)
q){value"\q -p ",string x}each 6000+til 2;
q).z.pd:`u#hopen each 6000+til 2
q)count distinct{10?20}peach til 1000 // uniqueness not maintained across slave processes
502
q)count distinct({10?20}each til 1000),{10?20}peach til 1000 // uniqueness not maintained across master+slaves
1002
q)
q){value"\q -p ",string x}each 20000+til 2; // ports 20000 & above as per notes
q).z.pd:`u#hopen each 20000+til 2
q)count distinct{10?20}peach til 1000 // unique across slaves
1000
q)count distinct({10?20}each til 1000),{10?20}peach til 1000 // unique across master+slaves
2000