Random Boolean or Percentage (v5)

Revision 5 of this benchmark created on


Description

Is there a difference between randomize between 0 and 1 and 0 and 100? For those cases where you need only 2 possibilities (like heads and tails).

Test runner

Ready to run.

Testing in
TestOps/sec
Boolean
var ran_number = !! Math.round(Math.random() * 1);

if (!ran_number) {
 return 'lower_than_50pct';
} else {
 return 'higher_than_50pct';
}
ready
Percentage
var ran_number = Math.ceil(Math.random() * 100);

if (ran_number <= 50) {
 return 'lower_than_50pct';
} else {
 return 'higher_than_50pct';
}
ready
round random
var ran_number = Math.round(Math.random());

if (ran_number) {
 return 'lower_than_50pct';
} else {
 return 'higher_than_50pct';
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.