How reliable is the Random function in Delphi

前端 未结 9 1345
遥遥无期
遥遥无期 2020-12-30 06:53

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

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 07:03

    Delphi's PRNG, like almost all programming language RTL PRNGs, is a linear congruential generator.

    It's good enough for most small-scale things, but there are things to watch out for. In particular, watch out for low-order bits: the pattern of multiplication and add means that low-order bits are not very random at all. But this generally only applies to large 32-bit values pulled out and then truncated with mod or similar. Using Random(10) to pluck a value between 0 and 9 internally uses a multiplication over the whole 32-bit range rather than a mod operation.

提交回复
热议问题