srand in D
kdevel
kdevel at vogtner.de
Sun Jan 9 00:17:22 UTC 2022
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.
> TIL, I can use uniform with a type as in uniform!Fruit. Pretty
> cool. :)
nice. But
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);
complains with
uni2.d(11): Error: template instance `uniform!(['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'])` has no value
More information about the Digitalmars-d-learn
mailing list