uniform_real_distribution should use uniform_int_distribution
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start at the generate_uniform_real entry point and compare the integral-engine path with the behavior described in the issue. Exercise it with an engine producing only 0 and 1, then verify that the resulting real distribution can produce more distinct values while preserving the intended range.
Written by the indexing model from the issue text.
Description
Hello again!
generate_uniform_real for is_integral<Engine::result_type> == true should probably do something like this (pseudo code):
auto dist = uniform_int_distribution<unsigned long>( unsigned long min, unsigned long max );
auto numerator = dist(eng);
auto divisor = unsigned long max;
[...]
instead of using:
result_type numerator = static_cast<T>(subtract<base_result>()(eng(), (eng.min)()));
result_type divisor = static_cast<T>(subtract<base_result>()((eng.max)(), (eng.min)())) + 1;
[...]
The current implementation fails to produce more different values than the range of the Engine is able to give. E.g., a PRNG which only ever produces values in the range [0..1] would lead to returning only 2 different real values.
What are your thoughts about this?
Best regards,
Dominik
PS: I noticed this when using good ol' rand() as an Engine behind the scenes.
- Dominant language
- C++
- Stars
- 42
- Forks
- 76
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 6
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/random
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Documentation
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100