Improved Random Number Generation
The Random function is often used to generate sequences of random numbers in Delphi applications. By default this function generates the same sequence of random numbers each time the parent application is executed. It is possible to generate different sequences by seeding the random number generator using the Randomize function.
However, this is often not adequate - the underlying algorithm used by Random is too simple to offer any guarantee that the sequences generated will be truly unique. Ultimately, any software generated random number sequence is not truly random - there is an underlying algorithm with precise logic. Logic and random behavior do not make good bedfellows. It is not difficult to find algorithms of increased complexity that yield random number sequences that are more random
. However, it is not really necessary to code a new algorithm. Windows comes with an inbuilt random number generator - the CoCreateGUID function. The algorithm used to generate GUIDs is very complex. While it would be unsafe to assume that the sequence generated is anything other than pseudo-random, there is nevertheless a far lower probability of generating the same sequence than with any algorithm that the average programmer can reasonably hope to code. The download below contains a demonstration of the use of CoCreateGUID for the generation of robust random number sequences.