[net.math] random bignums

bts@mcnc.UUCP (Bruce T. Smith) (03/07/85)

Does anyone have suggestions for generating random bignums?
Currently, we're using several calls to random-- shifting
and adding each time-- to generate a number bigger than we
need.  Then we mod this by the desired upper bound.
_____________________________
Bruce T. Smith, MCNC           Microelectronics Center of N.C.
decvax!mcnc!bts      (USENET)  P.O. Box 12889, 3021 Cornwallis Rd.
bts.mcnc@CSnet-Relay (others)  Research Triangle Park, NC 27709

pmontgom@sdcrdcf.UUCP (Peter Montgomery) (03/17/85)

In article <2630@mcnc.UUCP> version B 2.10.2 9/18/84; site sdcrdcf.UUCP version B 2.10.1 6/24/83; site mcnc.UUCP sdcrdcf!hplabs!tektronix!uw-beaver!cornell!vax135!houxm!mhuxj!mhuxr!ulysses!unc!mcnc!bts bts@mcnc.UUCP (Bruce T. Smith) writes:
>Does anyone have suggestions for generating random bignums?
>Currently, we're using several calls to random-- shifting
>and adding each time-- to generate a number bigger than we
>need.  Then we mod this by the desired upper bound.
>_____________________________
>Bruce T. Smith, MCNC           Microelectronics Center of N.C.
>decvax!mcnc!bts      (USENET)  P.O. Box 12889, 3021 Cornwallis Rd.
>bts.mcnc@CSnet-Relay (others)  Research Triangle Park, NC 27709

Suppose we need to generate a random number between 0 and 123456789, and
our multi-precision routines work in base 1000.  I generate the bottom
three digits by taking one random integer between 0 and 999 inclusive, the
middle three digits likewise, and the upper three digits by taking a random
integer from 0 to 123.  The result will be a random number between 0 and
123999999.  If the result exceeds 123456789, then I reject it and start
afresh.  Otherwise I use this as my answer.
-- 
			Peter Montgomery

	{aero,allegra,bmcg,burdvax,hplabs,
	 ihnp4,psivax,randvax,sdcsvax,trwrb}!sdcrdcf!pmontgom

Don't blame me for the crowded freeways - I don't drive.

ndiamond@watdaisy.UUCP (Norman Diamond) (03/18/85)

> Suppose we need to generate a random number between 0 and 123456789, and
> our multi-precision routines work in base 1000.  I generate the bottom
> three digits by taking one random integer between 0 and 999 inclusive, the
> middle three digits likewise ...
> 			Peter Montgomery

You'll have to generate the middle digits independently of the lower digits.
Don't use the next sequential pseudo-random integer.  In fact, don't even use
the same formula with different seeds.  You need a different generator with
no correlation.

(Ditto for the top digits, only harder...)

-- 

   Norman Diamond

UUCP:  {decvax|utzoo|ihnp4|allegra}!watmath!watdaisy!ndiamond
CSNET: ndiamond%watdaisy@waterloo.csnet
ARPA:  ndiamond%watdaisy%waterloo.csnet@csnet-relay.arpa

"Opinions are those of the keyboard, and do not reflect on me or higher-ups."