mz.c

Tim Smith tim at ism780c.UUCP
Sat Nov 8 10:32:57 AEST 1986


Note: followups are being redirected to net.sources.d

In article <1125 at cit-vax.Caltech.Edu> trent at cit-vax.UUCP (Ray Trent) writes:
>
>I suppose this works...but isn't:
>
>     #define oneof(n)    (rand() % (n) + 1)
>
>more intuitive and efficient?

Yes, but it also doesn't work!  If n is not a divisor of 32768, the
distribution will be off.  For example, if n is 24000, then numbers
from 1 to 8000 will be given twice as often as numbers from 9000 to 24000.

-- 
emordnilapanalpanama

Tim Smith       USENET: sdcrdcf!ism780c!tim   Compuserve: 72257,3706
                Delphi or GEnie: mnementh



More information about the Comp.sources.unix mailing list