Random of zero

Wil Dijkstra W.Dijkstra at fsw.vu.nl
Wed May 14 08:33:01 EDT 2003


Shari,

The randomseed in MC is a positive integer. It changes everytime you start up MC. It is used (I suppose) to generate the very first random number, which is used in turn to generate next one. If you change the randomseed to a particular number (e.g. set randomseed to 1215312361), you will observe that random (x) generates the same number.
As far as I know, in all languages a random function exist. Only statisticians and numerical mathematicians write their own random generators. In HyperCard the maximum size of the parameter is 32768 (2^15). The quality of the random generator highly depends both on the size of a and of m (maximum) in z[n] = a*z[n-1] mod m. a = 630360016 and m = 2^31-1 appear to generate random numbers of high quality. There is an awful lot of theory behind the selection of such numbers, you don't want to know (:-)).
HyperCard apparently uses a maximum of m = 32768, which clearly produces random numbers that are not evenly distributed (as you noticed). But don't be surprised if the same number appears a number of times in succession if you simulate throwing a dice! For example, if you toss a coin, the chance that a large number of tails occur in succession is much larger than you intuitively would expect.
Random generators are never completely random; you're perfectly right. But you should never 'correct' suspect successions of a random generator, e.g. neglecting a dice roll if the same number occurs the nth time in succession. Whatever the quality of a random generator, it is always (much) better than a human being letting generate random numbers.
If you doubt if the simulated dice roll yields numbers that are evenly distributed (and they should, I agree), you can test it of course. If the generated number is n (from 1,2,...,6), just add 1 to the (array) variable x[n] and at the end of the run you will have a nice distribution of the numbers. You should do this some million times... And you should restart MC each time to produce a different randomseed. If, for example the number 5 occurs 10% of the time too often, you can write a function that -- randomly! -- neglects a 5 10% of the times. If the results are different for different randomSeeds, you can try to set the randomseed to a particular number, although I don't have the faintest  idea if this will affect the results (i don't know how MC is programmed).

Wil Dijkstra


> >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
> -- 
> --Shareware Games for the Mac--
> http://www.gypsyware.com
> _______________________________________________
> metacard mailing list
> metacard at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/metacard
> 
> 



More information about the metacard mailing list