Generating a uniform distribution of INTEGERS in C

后端 未结 4 1089
情书的邮戳
情书的邮戳 2020-12-01 09:48

I\'ve written a C function that I think selects integers from a uniform distribution with range [rangeLow, rangeHigh], inclusive. This isn\

4条回答
  •  我在风中等你
    2020-12-01 10:39

    I think it is known that rand() is not very good. It just depends on how good of "random" data you need.

    • http://www.azillionmonkeys.com/qed/random.html
    • http://www.linuxquestions.org/questions/programming-9/generating-random-numbers-in-c-378358/
    • http://forums.indiegamer.com/showthread.php?9460-Using-C-rand%28%29-isn-t-as-bad-as-previously-thought

    I suppose you could write a test then calculate the chi-squared value to see how good your uniform generator is:

    http://en.wikipedia.org/wiki/Pearson%27s_chi-squared_test

    Depending on your use (don't use this for your online poker shuffler), you might consider a LFSR

    http://en.wikipedia.org/wiki/Linear_feedback_shift_register

    It may be faster, if you just want some psuedo-random output. Also, supposedly they can be uniform, although I haven't studied the math enough to back up that claim.

提交回复
热议问题