Thread overview | ||||||
---|---|---|---|---|---|---|
|
April 29, 2019 srand time error uint/long | ||||
---|---|---|---|---|
| ||||
How to call srand() with time()? ``` void main() { import core.stdc.stdlib : rand, srand; import core.stdc.time : time; srand(time(null)); } ``` Error: function core.stdc.stdlib.srand(uint seed) is not callable using argument types (long) cannot pass argument time(null) of type long to parameter uint seed https://run.dlang.io/is/ner0Lx And how to use the d libs instead? is this the way to go? ``` Random rnd = Random(Clock.currTime().second); uniform01(rnd); //(or whatever) ``` |
April 30, 2019 Re: srand time error uint/long | ||||
---|---|---|---|---|
| ||||
Posted in reply to number | float f = uniform01(); Its already initialized on module load. If you do want to custom seed it, you'll probably want to cast the seed to uint instead and have your own instance of the random number generator. |
April 29, 2019 Re: srand time error uint/long | ||||
---|---|---|---|---|
| ||||
Posted in reply to number | On Monday, 29 April 2019 at 14:36:49 UTC, number wrote: > And how to use the d libs instead? is this the way to go? > > ``` > Random rnd = Random(Clock.currTime().second); > uniform01(rnd); //(or whatever) > ``` https://dlang.org/phobos/std_random.html#unpredictableSeed |
April 29, 2019 Re: srand time error uint/long | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | On Monday, 29 April 2019 at 14:39:29 UTC, rikki cattermole wrote: > float f = uniform01(); > > Its already initialized on module load. > > If you do want to custom seed it, you'll probably want to cast the seed to uint instead and have your own instance of the random number generator. On Monday, 29 April 2019 at 15:24:41 UTC, Paul Backus wrote: > https://dlang.org/phobos/std_random.html#unpredictableSeed Thanks! |
Copyright © 1999-2021 by the D Language Foundation