[squeak-dev] The Inbox: Network-topa.165.mcz

Levente Uzonyi leves at elte.hu
Tue Oct 20 17:05:20 UTC 2015

On Tue, 20 Oct 2015, Tobias Pape wrote:

> Hi all,
> On 20.10.2015, at 07:53, Levente Uzonyi <leves at elte.hu> wrote:
>> Hi Tobias,
>> TheRandom should be re-seeded on startup, so that images don't generate the same UUIDs.
>> Integer >> atRandom: creates a random number between 1 and the receiver,
>> so 16rffffffffffffffffffffffffffffffff atRandom: TheRandom won't create
>> all possible 128-bit values. It's also a bit slow to create an intermediate Integer objects for this, so I suggest you should use Random
>>>> #nextBytes:into:startingAt: instead to fill the UUID object with random
>> bytes.
> I thought about going back to ThreadSafeRandom, it seems more fit.

That wouldn't help either, because if you don't reseed the generator on 
startup, then it will produce the same numbers in the same order each 
time the image is launched.
ThreadSafeRandom has another weakness - more general one: it's slow if you
repeatedly fork a thread, generate a random value and abandon the thread, 
because a new generator will be initialized for each thread. Such usage 
pattern also decreases the randomness of the generated numbers, because 
currently the seed is always truncated to 32-bits, while the internal 
state is much larger. This should be changed.

> About the speed, I was actually quite happy with it ;)
> But I see your point.

I found that not creating an intermediate integer gives another 2x 
speedup, which makes it easier to accept not using the primitive.


> Best regards
> 	-Tobias

More information about the Squeak-dev mailing list