From: "Earl F. Glynn" Subject: Re: Delphi's Random Number Generator Date: Friday, October 06, 2000 8:50 AM John: > We are using Borland's Random Number Generator for Statistical > Sampling. Our Auditors need to know about the > Random number formula the Random Procedure uses to generate > random numbers. Can you tell us the name of the formula used, > and what the formula is? The Random function uses "compiler magic" to decide whether it returns an integer or floating-point extended result. For an integer result, _RandInt in System.PAS is called. For an extended result, _RandExt in System.PAS is called. Here are the assembly language routines from System.PAS: procedure _RandInt; asm { ->EAX Range } { <-EAX Result } IMUL EDX,RandSeed,08088405H INC EDX MOV RandSeed,EDX MUL EDX MOV EAX,EDX end; procedure _RandExt; const two2neg32: double = ((1.0/\$10000) / \$10000); // 2^-32 asm { FUNCTION _RandExt: Extended; } IMUL EDX,RandSeed,08088405H INC EDX MOV RandSeed,EDX FLD two2neg32 PUSH 0 PUSH EDX FILD qword ptr [ESP] ADD ESP,8 FMULP ST(1), ST(0) end; RandSeed can be set directly or through a call to Randomize. In Ray Lishner's "Delphi in a NutShell" he says: "Delphi uses a pseudorandom number generator (PRNG) with a cycle of 2^32. Although adequate for simple simulations, it is not suitable for use in encrption or other areas where you need a high-quality PRNG." I don't know whether your auditors will like that statement or not. For alternative random number generators, try: - Fast BASM implementation of the "Mother-of-all Pseudo Random Number Generators" as proposed by well-known random number guru, Dr. George Marsaglia of the Department of Statistics, Florida State University. Freeware with source code. www.mindspring.com/~efd/tools.htm (Perhaps your auditors would like a Florida professor's work!) Ultimate Random Number Suite http://www.engineeringobjects.com/URNS.htm I keep info about Random number generators in Delphi in the Probability and Links sections of this page: http://www.efg2.com/Lab/Library/Delphi/MathFunctions/StatisticsAndProbability.htm