# Random Boolean or Percentage (v7)

## 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

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';
}``````
Percentage
``````var ran_number = Math.ceil(Math.random() * 100);

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

if (ran_number) {
return 'lower_than_50pct';
} else {
return 'higher_than_50pct';
}``````
!*2<<0
``````var ran_number = !(Math.random()*2<<0);

if (ran_number) {
return 'lower_than_50pct';
} else {
return 'higher_than_50pct';
}``````
*2<<0
``````var ran_number = Math.random()*2<<0;

if (ran_number) {
return 'lower_than_50pct';
} else {
return 'higher_than_50pct';
}``````
Math.random()<.5
``````var ran_number = Math.random()<.5; // Readable, succint

if (ran_number) {
return 'lower_than_50pct';
} else {
return 'higher_than_50pct';
}
``````
!(Math.random()+.5|0)
``````var ran_number = !(Math.random()+.5|0); // (shortcut for Math.round)

if (ran_number) {
return 'lower_than_50pct';
} else {
return 'higher_than_50pct';
}
``````
!(+new Date()%2);
``````var ran_number = !(+new Date()%2); // faux-randomness

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