Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!bcm!lib!thesis1.med.uth.tmc.edu From: dfenyes@thesis1.med.uth.tmc.edu (David Fenyes) Newsgroups: comp.unix.questions Subject: Re: random numbers in awk? Message-ID: <5066@lib.tmc.edu> Date: 23 May 91 15:17:02 GMT References: <1991Apr24.041134.14519@athena.mit.edu> <1136@mwtech.UUCP> <1991May13.221822.27731@gumby.dsd.TRW.COM> Sender: usenet@lib.tmc.edu Organization: University of Texas Medical School at Houston Lines: 43 Nntp-Posting-Host: thesis1.med.uth.tmc.edu In article <1991May13.221822.27731@gumby.dsd.TRW.COM> suhre@shark.dsd.trw.com.UUCP (Maurice E. Suhre) writes: >In article <1136@mwtech.UUCP> martin@mwtech.UUCP (Martin Weitzel) writes: >+SysV User's should note that they have a similar program, called random. >+It's range of output values is restricted to 0..255 (the upper limit must >+be specified as a calling argument). If you need larger numbers, you >+can, of course, call random twice, multiply the result of the first >+call by 256, add the result of the second call, and take the whole thing >+modulo the largest number you want. >Be advised that the operations mentioned (multiplication, modulo) will, >in general, change the distribution of the random numbers. That is, if you >started with uniformly distributed random numbers, then what you will >come out with will not be uniformly distributed. The dist. will be changed-- from uniform on 0...255 to uniform on 0...65535. The multiplication 'spreads' the pdf of the first call form 1/256 in each 'bin' from 0...255 to 1/256 in every 256'th bin from 0 to 65280. Addition of the second number convolves its pdf (0..255) with the first, 'filling out' the summed pdf to a unform distribution of 1/65536 from 0...65535. If the modulo is a power of 2, then the distribution of the pdf below the mod value will be uniform. (The distribution above the value will be perfectly mapped to the dist. below so that each 'bin' gets the same amount of added probability). If the mod value is NOT a power of 2, so that 633536 MOD n != 0, then the dist will be: from 0 to 65536 % n - 1: ([65536 / n] + 1) / 65536 from 65536 % n up: ([63336 / n]) / 65536 where [x] means the greatest integer <= x. Regards, David --------- David Fenyes dfenyes@thesis1.med.uth.tmc.edu University of Texas Medical School Houston, Texas