srand in D
Steven Schveighoffer
schveiguy at gmail.com
Tue Jan 11 02:21:33 UTC 2022
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 first Fruit happens to be
>> "mango" with that seed.
>
>
> enum Fruit { apple, mango, pear }
> version (X86_64)
> writeln(uniform!Fruit);
> ```
>
> This modified program delivers a fruit mix. Alas not in the online
> version, where one is supposed to have a preference for apples.
The online compiler caches results to save on computational resources.
So if you don't change the code, you will get the same result.
Just add spacing to get it to rebuild.
-Steve
More information about the Digitalmars-d-learn
mailing list