New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

random(low, high) can return high #4551

Closed
atgeflu opened this Issue Jun 30, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@atgeflu

atgeflu commented Jun 30, 2016

On the Processing.js github an issue was opened, that random(low,high) can return highwhen the interval low .. high is sufficiently small.

I thought that this might only be a Processing.js issue, but Processing (and P5.js) seem to be affected as well. (I've opened an issue for P5.js as well).

I guess this use case should be rather rare, but I thought you might still like to know about this issue.

Code example:


float answer;
int found1 = 0;
float myLow = 0.9999; 
int trials = 100000;

for (int i = 0; i < trials; i++) {
  answer = (random(myLow,1.0));
  if (answer >= 1) {
    found1++;
  }
}

println("highs found: " + (found1) + " (correct): " + (trials-(found1)));
@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Jul 28, 2016

Member

Ha, that's funny... It was implemented properly for the random(1) case but not the range. Now fixed for 3.1.2.

Member

benfry commented Jul 28, 2016

Ha, that's funny... It was implemented properly for the random(1) case but not the range. Now fixed for 3.1.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment