How to generate a random number from system clock as seed

Salih Dincer salihdb at hotmail.com
Sat Jun 8 20:07:10 UTC 2024


On Saturday, 8 June 2024 at 18:25:20 UTC, drug007 wrote:
> 
> ```d
>     {
>         const seed = castFrom!long.to!uint(Clock.currStdTime);
>         auto rng = Random(seed);
>         auto result = generate!(() => uniform(0, 10, 
> rng))().take(7);
> 	// new random numbers sequence every time
>         result.writeln;
>     }
> ```

If UnixTime is desired, it is sufficient to have 
currTime.toUnixTime instead of currStdTime. It will not reset 
until January 19, 2038.

```d
auto seed = to!uint(Clock.currTime.toUnixTime);
```

SDB at 79


More information about the Digitalmars-d-learn mailing list