[fpc-pascal] Why is Random(255) some 529x slower compared to Delphi 7?

Jorge Aldo G. de F. Junior jagfj80 at gmail.com
Wed Dec 7 17:46:08 CET 2011


Maybe implementing something other :

"The main advantages of the MWC method are that it invokes simple
computer integer arithmetic and leads to very fast generation of
sequences of random numbers with immense periods, ranging from around
260 to 22000000."

http://en.wikipedia.org/wiki/Multiply-with-carry

2011/12/7 Florian Klaempfl <florian at freepascal.org>:
> Am 07.12.2011 16:03, schrieb Graeme Geldenhuys:
>> On 7 December 2011 14:54, Jonas Maebe <jonas.maebe at ....> wrote:
>>>
>>> That's correct. We use the mersenne twister, Delphi probably a linear
>>> congruential generator. The mersenne twister has a much larger period.
>>
>> I was reading a bit more about this.  The Mersenne Twister (MT)
>> generator has a massive period of 2^19937-1, compared to the XorShift
>> generator, which in turn has a period of 2^128-1.
>>
>> Most text I read mentions that MT is great for statistical purposes,
>> and performs well in its class.
>>
>> So wouldn't it maybe make more sense to let the standard (read more
>> common) Random() call use a higher performance random number
>> generator, with a much lower period.
>
> Well, once we thought we try to do things better than Delphi ;) Some
> people, I think John Lee, asked for a better random in FPC years ago so
> Jonas implemented a MT.
>
>> Then add the MT generator as a
>> call to the Maths unit - where more statistical functions are located?
>>
>> Most applications are not statistical apps, they just want a random
>> number here or there, so such high period low performance generator is
>> normally not required. Having it in the Maths unit still makes in
>> available when needed though - for those specialised apps.
>>
>> Just a thought...
>>
>
> FPC uses MT at least for 10 years and nobody complained about
> performance yet. So I suspect the cases might be very rare when random
> performance matters and having good random numbers is always a good
> thing ... I prefer not to change it but it's fine for me for delphi
> compatibility's sake ;)
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal



More information about the fpc-pascal mailing list