I am writing a program which write statistical tests in Delphi (must be Delphi) and I've heard that the Random functionality is somewhat odd. You have to call randomize to randomize the seed of the random function when the program starts.
I'm wondering if the random function (after calling randomize) is random enough for statistical tests or a Mersenne twister is needed? Does anyone have any insight into random's actual implementation which can tell me how important this is?
Whether Random
is sufficiently reliable for your statistical tests will depend on the context in which you intend to use it.
Having said that, I have written several pieces of Delphi code that need to do proper statistics, and have used Random
e.g. for obtaining various null distributions, data pseudo-replications and resamplings. So far, I have not come across any case in my own code where Random
would have yielded biased or unreliable results, or results which would have precluded its use for the intended statistical test. But what holds for my code does not necessarily have to hold for yours.
If in doubt, you could of course statistically analyse the results of calls to Random
(e.g. in R, SPSS, etc.) and examine whether the distribution of results violate the distributional requirements for your particular statistical test(s). [If you're a proper scientist, this is what you should do anyway.]
Should you need other PRNGs - e.g. the TPMath library contains some. (For more involved things, there's also the option of calling elaborate statistical functions from R via Delphi.)