[fpc-devel] I get duplicate GUIDs under Linux
JeLlyFish.software at gmx.net
Mon Jun 2 20:11:16 CEST 2008
Vincent Snijders wrote:
> Klaus Hartnegg schreef:
>>> a call to randomize "disrupts" the current state of the random
>>> generator. That means that if you use random outside guid creation,
>>> creating a guid can have unintended side effects on your random
>> Maybe the GUID generator should have an automatic call to randomize,
>> but use its own randseed (or preserve the original value):
>> randseed_old := randseed;
>> if not guid_rnd_initialized then begin
>> guid_rnd_initialized := true;
>> randseed := guid_randseed;
>> result := rnd2guid(random);
>> guid_randseed := randseed;
>> randseed := randseed_old;
> It is not that easy to restore the state of random number generator.
"Not that easy" is quite an understatement here. ;) It's very close to
impossible without changing the System-unit. That was one issue I had.
The other one was simple that System's RNG is not thread-safe, so I
finally decided to use an RNG on a per object basis here.
This makes the necessary locking of a system wide RNG in threading
context much easier and additionally I can still use a "deterministic"
RNG in contexts where I need it, because now I can have as many
"dedicated" RNGs as I like. :)
Maybe, such Random class should be incorporated in the FCL, too?
More information about the fpc-devel