Not so Random Random Numbers

The ColdFusion Rand() and RandRange() functions are used to return random numbers, but the numbers generated are not truly random (no computer generated random numbers are). Random numbers are actually calculated and sequenced starting from an initial value (called a seed value), and if the same initial value is always used the “random” numbers will always be generated in the same sequence. The solution? Use the Randomize() function to set a different seed value each time you need random numbers. You can use a function like GetTickCount() to generate the seed value, or calculate it any way you see fit. (Applies to: ColdFusion All)

Leave a Reply