#1 2014-07-10 16:23:44

louis_riviera
Member
Registered: 2013-09-23
Posts: 61

Random()

Is there an alternative for this RTL random generator? It is not very fast or accurate.

An SSE optimized version would be nice but i cannot find any in SynCommons.pas

Offline

#2 2014-07-10 19:05:08

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,682
Website

Re: Random()

There is none in SynCommons.pas.

Up to now, we rely on Random() + GetTickCount for instance as RandomSeed().
It is enough for our purpose.
Then a hash (e.g. crc32 or SHA256) if real random is needed.

I suspect this implementation is pretty good and fast:
https://code.google.com/p/gpdelphiunits … domGen.pas

Offline

#3 2014-07-16 07:35:26

louis_riviera
Member
Registered: 2013-09-23
Posts: 61

Re: Random()

Random() is not thread safe at all. Because it is not a thread var. Plus 64 bit is a lot slower since its written in ASM.

Offline

#4 2014-07-16 09:36:44

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,682
Website

Re: Random()

You have to protect your call to Random(), or the code supplied at https://code.google.com/p/gpdelphiunits … domGen.pas with a critical section.

Offline

#5 2014-07-16 10:20:12

louis_riviera
Member
Registered: 2013-09-23
Posts: 61

Re: Random()

Is better to use threadvar IMHO. Locks are slower, much slower.

Offline

Board footer

Powered by FluxBB