{"action":"created","issue":{"url":"https://api.github.com/repos/processing/p5.js/issues/1495","repository_url":"https://api.github.com/repos/processing/p5.js","labels_url":"https://api.github.com/repos/processing/p5.js/issues/1495/labels{/name}","comments_url":"https://api.github.com/repos/processing/p5.js/issues/1495/comments","events_url":"https://api.github.com/repos/processing/p5.js/issues/1495/events","html_url":"https://github.com/processing/p5.js/issues/1495","id":163253749,"number":1495,"title":"random(low, high) can return high","user":{"login":"atgeflu","id":4339490,"avatar_url":"https://avatars.githubusercontent.com/u/4339490?v=3","gravatar_id":"","url":"https://api.github.com/users/atgeflu","html_url":"https://github.com/atgeflu","followers_url":"https://api.github.com/users/atgeflu/followers","following_url":"https://api.github.com/users/atgeflu/following{/other_user}","gists_url":"https://api.github.com/users/atgeflu/gists{/gist_id}","starred_url":"https://api.github.com/users/atgeflu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atgeflu/subscriptions","organizations_url":"https://api.github.com/users/atgeflu/orgs","repos_url":"https://api.github.com/users/atgeflu/repos","events_url":"https://api.github.com/users/atgeflu/events{/privacy}","received_events_url":"https://api.github.com/users/atgeflu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-06-30T19:58:14Z","updated_at":"2016-07-01T11:30:35Z","closed_at":null,"body":"On the Processing.js github an [issue](https://github.com/processing-js/processing-js/issues/244) was opened, that `random(low,high)` can return `high `when the interval `low .. high` is sufficiently small.\r\n\r\nI thought that this might only be a Processing.js issue, but Processing and P5.js seem to be affected as well. I've already opened a ticket for Processing as well.\r\n\r\nI guess this use case should be rather rare, but I thought you might still like to know about this issue.\r\n\r\nCode example:\r\n```\r\n\r\nfunction setup() \r\n{\r\n  noLoop();\r\n  \r\n  var answer;\r\n  var found1 = 0;\r\n  var myLow = 0.99999999999;\r\n  var trials = 10000000;\r\n  for (var i = 0; i < trials; i++) {\r\n    answer = random(myLow, 1);\r\n    if (answer >= 1) {\r\n      found1++;\r\n    }\r\n  }\r\n  println(\"highs found: \" + (found1) + \" (correct): \" + (trials-(found1)));\r\n} \r\n```"},"comment":{"url":"https://api.github.com/repos/processing/p5.js/issues/comments/229924373","html_url":"https://github.com/processing/p5.js/issues/1495#issuecomment-229924373","issue_url":"https://api.github.com/repos/processing/p5.js/issues/1495","id":229924373,"user":{"login":"atgeflu","id":4339490,"avatar_url":"https://avatars.githubusercontent.com/u/4339490?v=3","gravatar_id":"","url":"https://api.github.com/users/atgeflu","html_url":"https://github.com/atgeflu","followers_url":"https://api.github.com/users/atgeflu/followers","following_url":"https://api.github.com/users/atgeflu/following{/other_user}","gists_url":"https://api.github.com/users/atgeflu/gists{/gist_id}","starred_url":"https://api.github.com/users/atgeflu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atgeflu/subscriptions","organizations_url":"https://api.github.com/users/atgeflu/orgs","repos_url":"https://api.github.com/users/atgeflu/repos","events_url":"https://api.github.com/users/atgeflu/events{/privacy}","received_events_url":"https://api.github.com/users/atgeflu/received_events","type":"User","site_admin":false},"created_at":"2016-07-01T11:30:34Z","updated_at":"2016-07-01T11:30:34Z","body":"@limzykenneth Thanks a lot for pointing this out and for the link to the video on floating point numbers. \r\n\r\nIn light of this, I guess it might make sense to close the issue. \r\n\r\nMaybe it would be a good idea to add some information to the current reference on the random() function about the possibility that `high` might be returned in rare cases due to the way floating point arithmetic works (perhaps with a link to aforementioned video). That way if someone runs into this again in the future a check of the reference would suffice for them to see why the issue happens. \r\n"}}
{"actor":{"display_login":"atgeflu"}}