Documentation of std.random.dice is very poor.
I’ve used that function in the past, yet had to read through it a few times to get how it workes.
to be honest, my first thought after reading it for the first time was like:
> Has the author ever held a dice in their hand!?
Let me elaborate:
A real-world dice, mathematically called a «fair dice», is usually labelled 1,2,3,4,5,6; where each side has the very same probability (1÷6).
The first number mentioned in the documentation is «0.5». That’s kinda unexpected.
Neither 50-50, 70 or 42 (you can find all of them in the docs) is what I’d expect either.
The first example should be how to code a real-world-alike «fair dice» with numbers 1 … 6.
Feel free to explain the advanced stuff afterwards.
But keep in mind: It does *not* reassemble a real world dice…
Paul Backus on Discord about this matter:
> Literally the worst-named function in Phobos.
> It should be called something lime `weightedChoice`.
> As you’ve noticed, it has noting at all to do with dice
- Elias
Comment #1 by desisma — 2022-07-24T03:11:01Z
Paul wrote «something like», that «lime» typo is my fault. sorry :/
Comment #2 by dlang-bot — 2022-07-25T09:11:53Z
@dkorpel created dlang/phobos pull request #8519 "Fix 23270 - std.random.dice is poorly documented" fixing this issue:
- Fix 23270 - std.random.dice is poorly documented
https://github.com/dlang/phobos/pull/8519
Comment #3 by dlang-bot — 2022-07-25T11:56:17Z
dlang/phobos pull request #8519 "Fix 23270 - std.random.dice is poorly documented" was merged into master:
- 80e0fa23e85c6d8b6e1338fed205b01a6adad815 by Dennis Korpel:
Fix 23270 - std.random.dice is poorly documented
https://github.com/dlang/phobos/pull/8519