Ticket #1479 (new todo)

Opened 5 years ago

Last modified 4 years ago

Improve random-ness of Parrot_range_rand

Reported by: Austin_Hastings Owned by:
Priority: normal Milestone:
Component: testing Version: 2.1.0
Severity: medium Keywords:
Cc: Language:
Patch status: Platform:

Description

Parrot_range_rand(min, max, ignored) returns a number between min and max, inclusive. However, it does so by computing a floating point number, multiplying that be the integer difference, and adding it to the min. The result of this, in C, is that truncating conversion introduces a bias away from max. Consider a call Parrot_range_rand(0, 10, 0) - the result is min (0 in our case) plus (max-min) (10-0, or 10) times a random number in the range 0.0 ... 1.0. But because of truncating conversion, 10*(rand) will convert to 0 about 10% of the time (0.000 ... 0.099), 1 about 10% of the time (0.100 ... 0.199), ..., and 9 about 10% of the time (0.900 ... 0.999). About 0% of the time (there is a change of hitting 1.0, but floats have a lot of decimal places...) the result will be 10.

Attachments

random-range.t Download (10.9 KB) - added by Austin_Hastings 5 years ago.
Proposed random-range.t test for t/dynoplibs

Change History

follow-up: ↓ 2   Changed 5 years ago by whiteknight

This should be fixed as of r44467. Will close after testing further.

in reply to: ↑ 1   Changed 5 years ago by jkeenan

Replying to whiteknight:

This should be fixed as of r44467. Will close after testing further.

Is there any test we could write that would demonstrate the problem and the solution?

Thanks.

kid51

  Changed 5 years ago by Austin_Hastings

I have written a chi-square test for this, but even though the tests now pass frequently (something that they did not do before), they still occasionally fail due to insufficient randomness.

Suggestions?

Changed 5 years ago by Austin_Hastings

Proposed random-range.t test for t/dynoplibs

  Changed 4 years ago by jkeenan

  • component changed from none to testing
Note: See TracTickets for help on using tickets.