#Per-Thread Variable Initialization (std.Random)

1 messages · Page 1 of 1 (latest)

shrewd lichen
#

Hey,

Is there any way to have a per-thread std.Random without having to check if it has been initialized before each usage?

The naive way would be a threadlocal std.random, and initialized flag and checking that when calling some next() method and if required initializing it. However, I'd like to avoid that explicit lazy initialization while ideally also avoiding explicit initialization on thread spawn (that's what I'd go with though if there is no way around it).

misty apex
#

%%std.crypto.Random

#

Bot doesn't work. See std.crypto.random

#

If you want to write it yourself I don't think you can get away from both

  1. Writing something to initialize one lazily.
    AND
  2. Writing something to initialize it on thread spawn.

Because then you only have the choice of it being initialized by magic instead.

shrewd lichen
#

Thank you.

While I expected that there is nothing similar, I was still hoping for some way to have "complex" threadlocal initialization, like it does already work for simple values with having a global like

threadlocal var y: i32 = 2;