Confusion about `Random`

jwatson-CO-edu real.name at colorado.edu
Fri Dec 23 15:13:12 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

Salih, I would like to implement this tactic, but I do not 
understand it.

What are you creating here?
```d
static this() { } // can try using
```

What is this operator?
```d
\*...*\ () => new Atom(rand01) \*...*\
```



More information about the Digitalmars-d-learn mailing list