D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 23270 - std.random.dice is poorly documented
Summary: std.random.dice is poorly documented
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 minor
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2022-07-24 03:10 UTC by Elias Batek (0xEAB)
Modified: 2022-07-25 11:56 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Elias Batek (0xEAB) 2022-07-24 03:10:00 UTC
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 Elias Batek (0xEAB) 2022-07-24 03:11:01 UTC
Paul wrote «something like», that «lime» typo is my fault. sorry :/
Comment 2 Dlang Bot 2022-07-25 09:11:53 UTC
@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 Dlang Bot 2022-07-25 11:56:17 UTC
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