I have found a bug in ?y where y is an extended
precision integer. The result should never be y,
but:
t=: ? 1e6 $ 12345x
+/t=12345
89
The last result should of course be 0.
I know how this can be fixed, but I would like to
verify that the algorithm for ?y is correct with the
mathematicians in this forum.
For y an extended precision number, ?y is computed
by t=.?y1 where y1 is a little bigger than y,
repeating until t is less than y. (The same y1
is used for a given y.) Assuming that ?m produces
uniform random numbers between 0 and m-1, does
this process give uniform random numbers between
0 and y-1?
For example, suppose we want to compute z=:?1e6$y=:12345.
y=: 12345
t=: ?2e6$20000
+/12345>t
1233158
z=: 1e6 {. (12345>t)#t
NB. various tests
(+/z)%#z
6170.3
12344%2
6172
(c%y) , (+/c>:z)%#z [ c=: ? y
0.993277 0.993333
(c%y) , (+/c>:z)%#z [ c=: ? y
0.43872 0.438943
(c%y) , (+/c>:z)%#z [ c=: ? y
0.593925 0.594519
(c%y) , (+/c>:z)%#z [ c=: ? y
0.315674 0.315579
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm