Skip to content

Instantly share code, notes, and snippets.

@julian-weinert
Created January 28, 2018 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julian-weinert/bcda33056da0bcd6d77a00c587389212 to your computer and use it in GitHub Desktop.
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.
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