Random of zero
Robert Brenstein
rjb at rz.uni-potsdam.de
Wed May 14 17:40:01 EDT 2003
>>How does the random function work?
>>Most, if not all random functions use:
>>z[n] = a * z [n-1] mod m
>
>So in a C/C++ language, or Pascal, or any of the non-English types,
>does a random(x) function exist, or does the programmer have to
>write their own random(x) function, as you show above?
>
>I often hear talk about *seeds* in random functions, which assumes
>the codewriter is operating at a baser level of coding than we are.
>I know MetaTalk offers randomseed as well.
>
>I've always suspected that random(x) is not always as random as one
>would expect -not specific to Metacard, I noticed this primarily in
>Hypercard, when I'd see the same number come up several times in
>succession, for example with a dice roll. Granted there are only
>six choices for the number, but I noticed that at any given time,
>there was usually one number that was hot, and came up more
>frequently than other numbers.
>
>This is useful info, as random(x) while usually it does not matter
>if a number or range of numbers is *hot*, but in some cases, it
>matters a lot.
>
>Very interesting stuff, indeedy :-)
>
>Shari C
Shari, there is a random function in practically every language. On
Mac, most of these simply rely on the function provided in the Mac
toolbox. Your suspicion is quite correct: computers do not really
produce true random numbers but so called pseudo-random numbers. In
practice, they produce sequences of pseudo-random numbers, each
sequence based on so called seed value. This is why one gets exactly
same "random" numbers each time the same seed is used. (This can be
useful for testing.) People who write their own random functions
simply create better pseudo-random sequences. Better meaning that
they don't wrap as quickly and have more even distribution. Using
seconds from some arbitrary date in the past as seed is a simple way
to ensure that you get a different sequence each time.
Robert
More information about the metacard
mailing list