The process described should yield uniform random numbers between 0
and y-1.
Following up on the tests in the original posting, we can put the
numbers into equal sized bins and then calculate a chi-square
statistic. If this is not significant, we can be somewhat assured
that the numbers are random.
f=:3 : 0"0
y=. 12345
t=. ?2e6$20000
z=. 1e6 {. (12345>t)#t
NB. 12345=15*823
bin=.<.@% &823
observed=.(bin z) #/. z
expected=.(#z)%15
chisquare=.+/(*:observed-expected)%expected
)
require '~addons/stats/base/distribution.ijs'
-.14&chisqcdf f i.5
0.262214 0.120479 0.124215 0.292923 0.68203
Best wishes,
John
Roger Hui wrote:
> 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
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm