Answers for "random bool in js"

6

javascript get random boolean

const randomBoolean = () => Math.random() >= 0.5;
Posted by: Guest on July-03-2020
48

javascript get random boolean

console.log(Math.random() < 0.1); //10% probability of getting true
console.log(Math.random() < 0.4); //40% probability of getting true
console.log(Math.random() < 0.5); //50% probability of getting true
console.log(Math.random() < 0.8); //80% probability of getting true
console.log(Math.random() < 0.9); //90% probability of getting true
Posted by: Guest on January-19-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language