How to generate a random number from system clock as seed

Eric P626 ericp at lariennalibrary.com
Sun Jun 9 13:37:19 UTC 2024


On Saturday, 8 June 2024 at 18:25:20 UTC, drug007 wrote:
>
> ~~~
>     {
>         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;
>     }
> }
> ~~~

I managed to use this piece of code and it worked.

~~~
uint seed = castFrom!long.to!uint(Clock.currStdTime);
auto rng = Random(seed);
~~~

I am not exactly sure what the exclamation points stand for in 
the first line of code. Probably, defining a type to class 
```castFrom``` and function ```to```. But I get the idea that it 
just cast long to uint since ```Random``` requires an unsigned 
int.

I assume from this line of code that C casting like 
```(uint)varname``` would not work.




More information about the Digitalmars-d-learn mailing list