Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/globalscripts/random.js
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
* For example randIntExclusive(1.5, 3.5) yields 50% chance to get 2 and 25% chance for 1 and 3. | * For example randIntExclusive(1.5, 3.5) yields 50% chance to get 2 and 25% chance for 1 and 3. | ||||
*/ | */ | ||||
function randIntExclusive(min, max) | function randIntExclusive(min, max) | ||||
{ | { | ||||
return Math.floor(min + Math.random() * (max - min)); | return Math.floor(min + Math.random() * (max - min)); | ||||
} | } | ||||
/** | /** | ||||
* Returns true or false randomly. | * Returns a Bernoulli distributed boolean with p chance on true. | ||||
*/ | */ | ||||
function randBool() | function randBool(p) | ||||
{ | { | ||||
return Math.random() < 0.5; | return Math.random() < p; | ||||
} | } | ||||
elexis: ✓ |
Wildfire Games · Phabricator
✓