Confusion about `Random`

jwatson-CO-edu real.name at colorado.edu
Sat Dec 24 16:18:35 UTC 2022


On Friday, 23 December 2022 at 07:25:23 UTC, Salih Dincer wrote:
> You can try using static this.
>
> ```d
> import std.random;
>
> static this() { } // can try using
>
> Mt19937 rnd;
> void init_random() {
>   rnd = Random(unpredictableSeed);
> }
>
> double rand01() {
>     return uniform(0, 1.0, rnd);
> }
>
> void main()
> {
>   init_random();
>
>   struct Atom { double num; }
>   alias atom = Atom* function();
>   atom[string] primitiveSymbols = [
>     "rand" : () => new Atom(rand01)
>   ];
>   import std.stdio;
>   writeln(*primitiveSymbols["rand"]()); // Atom(0.630001)
> }
> ```
> SDB at 79

I would still like to learn about this idiom.  Can you tell me 
what it means and when I should use it?


More information about the Digitalmars-d-learn mailing list