J random-number generator: what is used?
Author Message
J random-number generator: what is used?

Does anyone know the algorithm, or the characteristics, of
the generator used for the ? operator in J?

Henry Rich

Wed, 21 May 1997 05:44:31 GMT
J random-number generator: what is used?
Henry Rich:
: Does anyone know the algorithm, or the characteristics, of the
: generator used for the ? operator in J?

From the file v.c in J7:
/* ----------------------------------------------------------------------- */
/* J-Source Version 7 - COPYRIGHT 1993 Iverson Software Inc.               */
/* 33 Major Street, Toronto, Ontario, Canada, M5S 2K9, (416) 925 6096      */
/*                                                                         */
/* J-Source is provided "as is" without warranty of any kind.              */
/*                                                                         */
/* J-Source Version 7 license agreement:  You may use, copy, and           */
/* modify the source.  You have a non-exclusive, royalty-free right        */
/* to redistribute source and executable files.                            */
/* ----------------------------------------------------------------------- */
/*                                                                         */
/* Verbs                                                                   */

F1(roll){A z;D rl=qrl;static D m=16807,p=2147483647L;I c,n,*v,*x;
RZ(w=vi(w));
n=AN(w); v=AV(w);
RZ(z=reshape(shape(w),two)); x=AV(z);
if(ICMP(v,x,n))
DO(n, c=*v++; ASSERT(0<c,EVDOMAIN); rl=fmod(rl*m,p); *x++=(I)floor(rl*c/p);)
else{B*x;D q=p/2;
GA(z,BOOL,n,AR(w),AS(w)); x=(B*)AV(z);
DO(n, rl=fmod(rl*m,p); *x++=rl>q;);
}
qrl=rl;
R z;

Quote:
}  /* P.C. Berry, Sharp APL Reference Manual, 1979, p. 126. */

F2(deal){A y;D rl=qrl;static D m=16807,p=2147483647L;I am,j,k,wm,*yv;
F2RANK(0,0,deal,0);
am=i0(a);
wm=i0(w);
ASSERT(0<=am&&am<=wm,EVDOMAIN);
RZ(y=apv(wm,wm-1,-1L)); yv=AV(y);
DO(am, rl=fmod(rl*m,p); j=i+(I)floor(rl*(wm-i)/(1+p)); k=yv[i]; yv[i]=yv[j]; yv[j]=k;);
qrl=rl;
R take(a,y);

Quote:
}  /* P.C. Berry, Sharp APL Reference Manual, 1979, p. 178. */

......................................................................

Does this help?

[These are c function declarations.  F1( begins the definition of a
monadic handler with argument w, F2( begins the definition of a dyadic
handler with arguments a and w.  RZ( returns 0 (error) if its argument
is zero.  DO(n, expr) performs the calculation expr n times.  R is
shorthand for C's "return" command.]

[Alternatively, you could look up the Sharp APL Reference Manual.]

--

1=t|e*d    NB. (,-:<:)pq is four large primes, e medium

Thu, 22 May 1997 03:00:13 GMT
J random-number generator: what is used?

Quote:

>Subject: J random-number generator: what is used?
>Date: 2 Dec 1994 16:44:31 -0500
>Does anyone know the algorithm, or the characteristics, of
>the generator used for the ? operator in J?
>Henry Rich

It's the Lewis, Miller, Goodman generator, the same as in APL. It is
the multiplicative congruential generator
x_{n+1)=7^5 x_n mod 2^31 - 1

For characteristics look up the following article:

Park, Miller: Random Number Generators: Good ones are hard to find
Communications of the ACM, Vol 31, No 10, October 1988

Sat, 24 May 1997 23:25:49 GMT
J random-number generator: what is used?
Henry Rich writes :

Quote:
>: Does anyone know the algorithm, or the characteristics, of the
>: generator used for the ? operator in J?

According to "An Implementation of J" it is something like :

roll =. (<:2^31)^tick"0

See {\it SHARP APL Reference Manual} p. 125 (Berry[1979]).

From the point of view of fast performance it could easily
be improved upon. For example, you'll see a BIG difference
in execution times between J and C upon comparing simulation
times of 100 instances of 1,000,000 random numbers.

If you are programming on a UNIX platform and doing serious
simulation I recommend integrating the pd RNG Mrandom
into the interpreter since it is best suited to J's A struct.
(You can allocate memory and then get the RN in one function
call).

-e

-e

Sun, 25 May 1997 16:22:26 GMT
J random-number generator: what is used?
To be precise:
Park + Miller call the APL generator: "minimal standard". It is from the
class of the so called "prime modulus multiplicative linear congruential
generators (PMMLCG)" also called "Lehmer genrators".
Berni

Sun, 25 May 1997 18:56:00 GMT
J random-number generator: what is used?
Quote:

>Henry Rich writes :

>>: Does anyone know the algorithm, or the characteristics, of the
>>: generator used for the ? operator in J?

>See {\it SHARP APL Reference Manual} p. 125 (Berry[1979]).

Paul Berry and I jointly rewrote this manual to bring it up to
date a while ago. It's available from Soliton Associates and
also from Iverson Software Inc.

Bob

Mon, 26 May 1997 03:22:36 GMT
J random-number generator: what is used?

Quote:

>-e>     See {\it SHARP APL Reference Manual} p. 125 (Berry[1979]).

>I'm just a bit curious:  How is this one related to
>Iverson: "APL Reference Manual", (c) 1993 Soliton Associates,
>This manual documents APL as provided in systems from
>Iverson Software Inc.  This dialect is based on Version 20
>of SHARP APL.''
>It has SHARP APL Reference Manual'' printed in every page header.

a. The 1993 Soliton manual is a total rewrite. It was initiated
by the APL Systems Development Department at I.P, Sharp Associates
back in the dark ages when I ran that group. We contracted the
job to Paul Berry. For various reasons that I won't go into,
this was shelved about 60% of the way along. Later on,
I completed the writing, figures, etc.,
under contract to what I think was still
Reuters at the time, although it may have turned into Soliton by
then. Elena Anzalone edited the entire document.
It is obviously a much more comprehensive work, that reflects
SHARP APL V20.

b. Iverson Software Inc. obtained a license for that work.
I do not know details of this, but I then reworked the
manual, along with Eric Iverson, to produce the ISIAPL
manual that ISI distributes. It may be that Soliton also
distributes that version...  I don't know.

Can't help more than that... Bob

Sun, 01 Jun 1997 04:18:32 GMT
J random-number generator: what is used?
-e>     See {\it SHARP APL Reference Manual} p. 125 (Berry[1979]).

I'm just a bit curious:  How is this one related to
Iverson: "APL Reference Manual", (c) 1993 Soliton Associates,
This manual documents APL as provided in systems from
Iverson Software Inc.  This dialect is based on Version 20
of SHARP APL.''
It has SHARP APL Reference Manual'' printed in every page header.

Martin Neitzel

Fri, 30 May 1997 22:09:39 GMT
J random-number generator: what is used?

Quote:

> How is this one related to Iverson: "APL Reference Manual"...

Further to Bob Bernecky's response:
The SHARP APL mainframe version was last revved in 1991 during our
incarnation as the APL Software Division of Reuters. Pub code is 1390 9109

I believe - I don't see a price for it in the latest Strand/ISI mailing but
I think it's in the 30 to 50 dollar range.

The history of these books is as Bob has stated. Paul Berry and Bob Bernecky
were the main contributors, Elena Anzalone edited the mainframe version and
Eric and Bob worked on the ISIAPL revisions.

Soliton Associates

Sun, 01 Jun 1997 22:48:36 GMT

 Page 1 of 1 [ 10 post ]

Relevant Pages