unit MATHUTYS; interface const MUID = '(c) J R Stockton www.merlyn.demon.co.uk >= 2008-03-18' ; // These have a 64-bit sequence; System.random is 32-bit // Effective randomness must be verified // These are inadequate for crypto; seek "Random" Web sites var RandSeed64 : UInt64 ; procedure Randomise64 ; function Random64 : extended ; overload ; function Random64(const UI64 : UInt64) : UInt64 ; overload ; implementation uses Windows ; {$OVERFLOWCHECKS ON} {$RANGECHECKS ON} const Factor = 6364136223846793005 { Said to be OK by Knuth } ; HalfTo64 = 1.0 / (65536.0 * 65536.0 * 65536.0 * 65536.0) ; procedure Randomise64 ; begin { B := } QueryPerformanceCounter(Int64(RandSeed64)) ; end {Randomise64} ; function Random64 : extended ; overload ; begin {$OVERFLOWCHECKS OFF} {$RANGECHECKS OFF} RandSeed64 := RandSeed64*Factor + 1 ; {$RANGECHECKS ON} {$OVERFLOWCHECKS ON} Result := RandSeed64*HalfTo64 ; end {Random64} ; function Random64(const UI64 : UInt64) : UInt64 ; overload ; begin Result := Trunc((Random64)*UI64) ; end {Random64} ; end.