Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.etla.org!aioe.org!.POSTED!not-for-mail From: pacman@kosh.dhis.org (Alan Curry) Newsgroups: comp.programming Subject: Re: Compare two methods of random permutations Date: Thu, 16 May 2013 06:57:48 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 27 Message-ID: References: <5f7c6014-dde2-4604-9f30-c544f3a336bb@k8g2000pbf.googlegroups.com> NNTP-Posting-Host: Zsfe989XKOK+vh5Qjv01Aw.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org Originator: pacman@kosh.dhis.org (Alan Curry) X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: trn 4.0-test77 (Sep 1, 2010) Xref: csiph.com comp.programming:3317 In article , Chris Uppal wrote: >James Dow Allen wrote: > >> Duh. Yeah. Note that the code snippet I posted assures, via >> do a = rand(); >> while (a >= 1916006400); >> that the requirements are met throughout. > >Missed that aspect of it myself. Shows the value of comments in code... > >But, why 1916006400 ? I may be missing something but it seems to me that >239500800 (12! / 2) would work just as well and not have a confusing/misleading >factor of 8 mismatch with the code. Whenever rand() returns something bigger than 1916006400 you have to call it again. And keep calling it until it gives you something good. If you lower the limit, you'll spend more time in the loop waiting for a usable random number. 1916006400 is the largest multiple of 239500800 that fits in a signed 32-bit integer, so it minimizes the number of rand() results that have to be thrown away. If your rand() doesn't return a signed 32-bit integer you should adjust the constant accordingly. -- Alan Curry