Here is my take on generating arbitrary large ranfom numbers.
dice=: 2&$: : (4 : 0)"0
y=. x #.^:_1 y-1
label_again.
l=.y =&{. r=.?1+{.y
while. l *. r<&#y do.
if. d>f=.y{~_1+#r=.r,d=.?x do. goto_again. end.
l=.d=f
end.
x #. r,?x#~y-&#r
)
This one seems to generate uniformly.
Changing left argument (which sets chunk size) performance can be tweaked.
6!:2 '1024 dice 3^8192x'
0.375183
6!:2 '4096 dice 3^8192x'
0.321426
6!:2 '8192 dice 3^8192x'
0.282104
6!:2 '9999 dice 3^8192x'
0.277032
6!:2 '10000 dice 3^8192x'
56.424
6!:2 '16384 dice 3^8192x'
59.269
9999 seems to be optimal, because
6!:2 '10000 #.^:_1]3^8192x'
57.244
6!:2 '9999 #.^:_1]3^8192x'
0.184827
Which, I guess, would also be nice to fix.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm