

















%   Purpose: Random number generator.

/*  This file needs 30-bit integers, or floating point, or both.
    The <<15 and >>15 are used to get binary fixed(30,15) arithmetic;
    floating point would do fine.  What we want is to take the
    fractional part of (A0/mod0+A1/mod1+A2/mod2).
*/

:- public
	random/2,
	random/3,
	rand_perm/2.

:- mode
	random(+, -),
	random(+, -, -),
	rand_perm(+, -).


%   given an integer N >= 1, random(N





























A1 = 9814, A2 = 20125
	),
	B0 is (A0*171) mod 30269,
	B1 is (A1*172)
 30307,
	B2 is (A2*170) mod 30323,
	asserta(seed(B0,B1,B2)),
	!,
is ((((A0<<15)/30269+(A1<<15)/30307+(A2<<15)/30323)/\32767)*
15.


%   given an non-empty List, random(List, Elem, Re
unifies Elem with
%   a random element of List and R
with the other elements.

random(List, Elem, Res
-
	length(List, N),






















































































