How reliable is the Random function in Delphi

前端 未结 9 1344
遥遥无期
遥遥无期 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:22

    Unless you buy some relatively esoteric hardware, the best approximation to random numbers a computer can provide is a completely deterministic pseudorandom sequence. In general, the randomize function uses some relatively random value (often based on the time, but sometimes on mouse movements - I have no idea what Delphi does) as a seed which provides the entry point to the pseudorandom sequence. Without this, you will end up getting back the same set of random numbers in the same order each time, which tends to defeat the purpose of using random numbers in the first place.

    Okay, I realize that this doesn't answer the question about reliability, but it should give you some confidence that requiring you to call randomize is a sign of a good generator rather than of a bad one. There are a bunch of statistical tests which show how random a sequence of numbers is, and it is likely that the Delphi random number generator is suitable for many purposes as it is a mature product.

提交回复
热议问题