Skip to content

Commit

Permalink
Update random.js
Browse files Browse the repository at this point in the history
Add a method for checking for a random chance/ probability of something happening
  • Loading branch information
BinaryMoon committed Feb 8, 2025
1 parent 80ed611 commit 283929c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/internal/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,21 @@
}


/**
* Returns a random boolean value based upon the probability percentage provided.
*
* @param {number} probability - A percentage value between 0 and 100 representing the chance of returning true.
* @returns {boolean} True with the specified probability, false otherwise.
*/
beep8.Random.chance = function( probability ) {

beep8.Utilities.checkNumber( "probability", probability );

return beep8.Random.num() < ( probability / 100 );

}


beep8.Random.setSeed();

} )( beep8 || ( beep8 = {} ) );
Expand Down

0 comments on commit 283929c

Please sign in to comment.