Created
January 28, 2018 13:12
-
-
Save julian-weinert/bcda33056da0bcd6d77a00c587389212 to your computer and use it in GitHub Desktop.
P5.js random rounding test; I'm comparing JavaScript rounding functions in P5 to prove that ceil and floor will omit one pissibility.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function evaluate(callback, from, to, count) { | |
var results = {}; | |
for (var i = 0; i < count; i++) { | |
var result = callback(from, to); | |
results[result] = results[result] ? results[result] + 1 : 1; | |
} | |
return results; | |
} | |
function setup() { | |
print(evaluate(function(from, to) { | |
return round(random(from, to)); | |
}, 1, 4, 1000)); | |
print(evaluate(function(from, to) { | |
return floor(random(from, to)); | |
}, 1, 4, 1000)); | |
print(evaluate(function(from, to) { | |
return ceil(random(from, to)); | |
}, 1, 4, 1000)); | |
} | |
function draw() { | |
noLoop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment