Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site sdcrdcf.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!sdcsvax!sdcrdcf!pmontgom From: pmontgom@sdcrdcf.UUCP (Peter Montgomery) Newsgroups: net.math Subject: Re: random bignums Message-ID: <1839@sdcrdcf.UUCP> Date: Sat, 16-Mar-85 21:48:48 EST Article-I.D.: sdcrdcf.1839 Posted: Sat Mar 16 21:48:48 1985 Date-Received: Mon, 18-Mar-85 07:38:33 EST References: <2630@mcnc.UUCP> Reply-To: pmontgom@sdcrdcf.UUCP (Peter Montgomery) Organization: System Development Corp. R+D, Santa Monica Lines: 24 Summary: 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.