Delphi中随机函数的可靠性如何 [英] How reliable is the Random function in Delphi
问题描述
我想知道随机函数(调用randomize之后)是否足够随机进行统计测试或需要Mersenne扭转器?有谁有任何洞察随机的实际实现,这可以告诉我这是多么重要?
是否随机
是足够可靠的,您的统计测试将取决于您打算使用它的上下文。
尽管如此,我已经写了几段需要正确统计的Delphi代码,并且使用了 Random
例如用于获得各种零分布,数据伪复制和重采样。到目前为止,我没有在我自己的代码中遇到任何情况,其中 Random
将产生有偏差或不可靠的结果,或者将排除其用于预期统计测试的结果。但是对于我的代码来说,不一定适用于您的代码。
如果有疑问,您可以统计分析调用结果随机
(例如在R,SPSS等),并检查结果的分布是否违反了您的特定统计测试的分布要求。 [如果你是一个正确的科学家,这是你应该做的。]
如果你需要其他PRNG,例如 TPMath 库包含一些。 (对于更多涉及的事情,还可以通过Delphi从R调用详细的统计功能。)
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.)
这篇关于Delphi中随机函数的可靠性如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!