Determines whether a random event occurs based on a given threshold.
Generates a random number between 0 (inclusive) and 1 (exclusive) and checks if it is greater than the provided threshold.
A number between 0 and 1 representing the probability threshold. A higher threshold decreases the chance of the event occurring.
true if the random number is greater than the threshold, otherwise false.
true
false
// 50% chance of returning trueconst result = randomChance(0.5);// 90% chance of returning falseconst unlikely = randomChance(0.9);// 10% chance of returning trueconst rareEvent = randomChance(0.1); Copy
// 50% chance of returning trueconst result = randomChance(0.5);// 90% chance of returning falseconst unlikely = randomChance(0.9);// 10% chance of returning trueconst rareEvent = randomChance(0.1);
Determines whether a random event occurs based on a given threshold.
Generates a random number between 0 (inclusive) and 1 (exclusive) and checks if it is greater than the provided threshold.