Re: How to generate a random number from system clock as seed

2024-06-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 8 June 2024 at 13:19:30 UTC, Eric P626 wrote: I managed to create a random number generator using the following code: ~~~ auto rng = Random(42); // uniform(0,10,rng); ~~~ Now I want to seed the generator using system time. I looked at Date & time functions/classes and systime

Re: How to generate a random number from system clock as seed

2024-06-10 Thread Eric P626 via Digitalmars-d-learn
On Sunday, 9 June 2024 at 23:31:47 UTC, drug007 wrote: ```d const seed = cast(uint) Clock.currStdTime; ``` Casting like this looks nice. It fits my type of thinking.

Re: How to generate a random number from system clock as seed

2024-06-09 Thread drug007 via Digitalmars-d-learn
On 09.06.2024 16:37, Eric P626 wrote: 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 number

Re: How to generate a random number from system clock as seed

2024-06-09 Thread monkyyy via Digitalmars-d-learn
On Sunday, 9 June 2024 at 07:11:22 UTC, Eric P626 wrote: On Saturday, 8 June 2024 at 21:04:16 UTC, monkyyy wrote: generate is a very rare function and do novices understand lamdas? Yes I know lamdas, but try not to use them. I am not very picky about the exact source of time, I just want a d

Re: How to generate a random number from system clock as seed

2024-06-09 Thread Eric P626 via Digitalmars-d-learn
On Sunday, 9 June 2024 at 13:20:09 UTC, Joseph Rushton Wakeling wrote: On Saturday, 8 June 2024 at 16:09:04 UTC, monkyyy wrote: rng is an optional parameter, `uniform(0,100).writeln;` alone works; the docs not telling you that is really bad The docs do tell you that `rng` is an optional parame

Re: How to generate a random number from system clock as seed

2024-06-09 Thread Eric P626 via Digitalmars-d-learn
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 res

Re: How to generate a random number from system clock as seed

2024-06-09 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On Saturday, 8 June 2024 at 16:09:04 UTC, monkyyy wrote: rng is an optional parameter, `uniform(0,100).writeln;` alone works; the docs not telling you that is really bad The docs do tell you that `rng` is an optional parameter of `uniform`: https://dlang.org/phobos/std_random.html#uniform Ho

Re: How to generate a random number from system clock as seed

2024-06-09 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On Saturday, 8 June 2024 at 13:19:30 UTC, Eric P626 wrote: Now I want to seed the generator using system time. Just to be clear, do you _specifically_ want to use the system time, or are you aiming to use the system time to generate different seeds for each run? If the latter you might pref

Re: How to generate a random number from system clock as seed

2024-06-09 Thread Eric P626 via Digitalmars-d-learn
On Saturday, 8 June 2024 at 21:04:16 UTC, monkyyy wrote: generate is a very rare function and do novices understand lamdas? Yes I know lamdas, but try not to use them. I am not very picky about the exact source of time, I just want a different integer every time I run the program. But while l

Re: How to generate a random number from system clock as seed

2024-06-08 Thread monkyyy via Digitalmars-d-learn
On Saturday, 8 June 2024 at 20:53:02 UTC, Nick Treleaven wrote: On Saturday, 8 June 2024 at 16:09:04 UTC, monkyyy wrote: rng is an optional parameter, `uniform(0,100).writeln;` alone works; the docs not telling you that is really bad They do tell you: urng (optional) random number generator

Re: How to generate a random number from system clock as seed

2024-06-08 Thread Nick Treleaven via Digitalmars-d-learn
On Saturday, 8 June 2024 at 16:09:04 UTC, monkyyy wrote: rng is an optional parameter, `uniform(0,100).writeln;` alone works; the docs not telling you that is really bad They do tell you: urng (optional) random number generator to use; if not specified, defaults to rndGen That overload is

Re: How to generate a random number from system clock as seed

2024-06-08 Thread Salih Dincer via Digitalmars-d-learn
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 re

Re: How to generate a random number from system clock as seed

2024-06-08 Thread drug007 via Digitalmars-d-learn
On 08.06.2024 16:19, Eric P626 wrote: I managed to create a random number generator using the following code: ~~~ auto rng = Random(42); // uniform(0,10,rng); ~~~ Now I want to seed the generator using system time. I looked at Date & time functions/classes and systime functions/classes. Th

Re: How to generate a random number from system clock as seed

2024-06-08 Thread monkyyy via Digitalmars-d-learn
On Saturday, 8 June 2024 at 13:19:30 UTC, Eric P626 wrote: I managed to create a random number generator using the following code: ~~~ auto rng = Random(42); // uniform(0,10,rng); ~~~ Now I want to seed the generator using system time. I looked at Date & time functions/classes and systime

Re: How to generate a random number from system clock as seed

2024-06-08 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 8 June 2024 at 13:19:30 UTC, Eric P626 wrote: I just want the number of seconds elapsed since jan 1st 1970. In other words, the internal system clock value. #unix #time @SDB79