Re: srand in D

2022-01-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/8/22 7:17 PM, kdevel wrote: On Saturday, 8 January 2022 at 23:34:17 UTC, Ali Çehreli wrote: [...] Apparently, the programmer wanted uniformly distributed randomness that is reproducible. That's why they use a generator that is seeded with 42 there. It does produce random results but the

Re: srand in D

2022-01-09 Thread kdevel via Digitalmars-d-learn
On Sunday, 9 January 2022 at 03:15:02 UTC, Ali Çehreli wrote: What would work in the code above is 'choice': char q = choice(allowed_chars); But that hits another fact of D: arrays of chars are strings, which cannot be RandomAccessRange because individual chars must be decoded to form dchar

Re: srand in D

2022-01-08 Thread Ali Çehreli via Digitalmars-d-learn
On 1/8/22 4:17 PM, kdevel wrote: > enum immutable (char) [] allowed_chars = [ >'c', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 't', 'v', >'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9' > ]; > > char q = uniform!allowed_chars; > writeln (q);

Re: srand in D

2022-01-08 Thread kdevel via Digitalmars-d-learn
On Saturday, 8 January 2022 at 23:34:17 UTC, Ali Çehreli wrote: [...] Apparently, the programmer wanted uniformly distributed randomness that is reproducible. That's why they use a generator that is seeded with 42 there. It does produce random results but the first Fruit happens to be "mango"

Re: srand in D

2022-01-08 Thread Ali Çehreli via Digitalmars-d-learn
On 1/8/22 12:27 PM, kdevel wrote: On Sunday, 31 October 2021 at 17:02:00 UTC, Ali Çehreli wrote: Just comment that line out. :) D's pseudo-random generators start randomized by default: [...]   https://dlang.org/phobos/std_random.html Klicking at "Run" always delivers "mango": https://dla

Re: srand in D

2022-01-08 Thread kdevel via Digitalmars-d-learn
On Sunday, 31 October 2021 at 17:02:00 UTC, Ali Çehreli wrote: Just comment that line out. :) D's pseudo-random generators start randomized by default: [...] https://dlang.org/phobos/std_random.html Klicking at "Run" always delivers "mango": https://dlang.org/phobos/std_random.html#unifo

Re: srand in D

2021-10-31 Thread pascal111 via Digitalmars-d-learn
On Sunday, 31 October 2021 at 17:02:00 UTC, Ali Çehreli wrote: On 10/31/21 9:54 AM, pascal111 wrote: Hi! I'm C learner and found the high similarity between C and D, and was converting C code into D Welcome! :) In case it makes to your use cases, check out -betterC as well: https://dlang.

Re: srand in D

2021-10-31 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 31 October 2021 at 16:54:35 UTC, pascal111 wrote: Hi! I'm C learner and found the high similarity between C and D, and was converting C code into D but couldn't get the equivalent of this C statement "srand(time(NULL));". Since D gives you access to the C standard library, you can u

Re: srand in D

2021-10-31 Thread Ali Çehreli via Digitalmars-d-learn
On 10/31/21 9:54 AM, pascal111 wrote: Hi! I'm C learner and found the high similarity between C and D, and was converting C code into D Welcome! :) In case it makes to your use cases, check out -betterC as well: https://dlang.org/spec/betterc.html > but couldn't get the equivalent of this C