X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f Date: Fri, 7 Sep 2007 21:07:08 -0400 Message-Id: <200709080107.l881789m001552@envy.delorie.com> From: DJ Delorie To: djgpp AT delorie DOT com In-reply-to: <60s3e31ouck81u9ti1njogqcoj1a5tfta3@4ax.com> (message from Brian Inglis on Sat, 08 Sep 2007 00:45:58 GMT) Subject: Re: random() : What am I doing wrong? References: <200709051534 DOT l85FYdil032635 AT envy DOT delorie DOT com> <60s3e31ouck81u9ti1njogqcoj1a5tfta3 AT 4ax DOT com> Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > IIRC the best distributed approach is to take a sufficient number of > bits b around the middle of the random integer, shift right to give you > a set 0..2^b-1 and if the number is bigger than you can use, try again > with a new random integer. If you use random(), it's already pulling bits out of the middle of its state machine. But the odds of needing to call random() twice are much lower if you check for the 49 values from 2,147,483,600 to 2,147,483,647, and use '%' to scale the remaining range.