diff --git a/data/mods/gen2/moves.ts b/data/mods/gen2/moves.ts index 634f0e89341f..58797d872151 100644 --- a/data/mods/gen2/moves.ts +++ b/data/mods/gen2/moves.ts @@ -590,7 +590,7 @@ export const Moves: import('../../../sim/dex-moves').ModdedMoveDataTable = { this.debug('Pursuit start'); let alreadyAdded = false; for (const source of this.effectState.sources) { - if (source.speed < pokemon.speed || (source.speed === pokemon.speed && this.random(2) === 0)) { + if (source.speed < pokemon.speed || (source.speed === pokemon.speed && this.randomChance(1, 2))) { // Destiny Bond ends if the switch action "outspeeds" the attacker, regardless of host pokemon.removeVolatile('destinybond'); } diff --git a/data/mods/gen5/conditions.ts b/data/mods/gen5/conditions.ts index 68bf4a6d5800..ed35741577fd 100644 --- a/data/mods/gen5/conditions.ts +++ b/data/mods/gen5/conditions.ts @@ -32,7 +32,7 @@ export const Conditions: import('../../../sim/dex-conditions').ModdedConditionDa // However, just in case, use 1 if it is undefined. const counter = this.effectState.counter || 1; if (counter >= 256) { - return this.random(0x100000000) === 0; // 2^32 + return this.randomChance(1, 2 ** 32); } this.debug("Success chance: " + Math.round(100 / counter) + "%"); return this.randomChance(1, counter); diff --git a/data/mods/gen9ssb/moves.ts b/data/mods/gen9ssb/moves.ts index 4c057850e281..cdbef5356fb5 100644 --- a/data/mods/gen9ssb/moves.ts +++ b/data/mods/gen9ssb/moves.ts @@ -2608,7 +2608,7 @@ export const Moves: import('../../../sim/dex-moves').ModdedMoveDataTable = { const spd = target.getStat('spd', false, true); const physical = Math.floor(Math.floor(Math.floor(Math.floor(2 * pokemon.level / 5 + 2) * 90 * atk) / def) / 50); const special = Math.floor(Math.floor(Math.floor(Math.floor(2 * pokemon.level / 5 + 2) * 90 * spa) / spd) / 50); - if (physical > special || (physical === special && this.random(2) === 0)) { + if (physical > special || (physical === special && this.randomChance(1, 2))) { move.category = 'Physical'; move.flags.contact = 1; } diff --git a/data/moves.ts b/data/moves.ts index 1305ab57fb6c..450b43398a9f 100644 --- a/data/moves.ts +++ b/data/moves.ts @@ -7352,7 +7352,7 @@ export const Moves: import('../sim/dex-moves').MoveDataTable = { isMax: "Snorlax", self: { onHit(source) { - if (this.random(2) === 0) return; + if (this.randomChance(1, 2)) return; for (const pokemon of source.alliesAndSelf()) { if (pokemon.item) continue; @@ -7448,12 +7448,12 @@ export const Moves: import('../sim/dex-moves').MoveDataTable = { isMax: "Grimmsnarl", onHit(target) { if (target.status || !target.runStatusImmunity('slp')) return; - if (this.random(2) === 0) return; + if (this.randomChance(1, 2)) return; target.addVolatile('yawn'); }, onAfterSubDamage(damage, target) { if (target.status || !target.runStatusImmunity('slp')) return; - if (this.random(2) === 0) return; + if (this.randomChance(1, 2)) return; target.addVolatile('yawn'); }, secondary: null, @@ -16814,7 +16814,7 @@ export const Moves: import('../sim/dex-moves').MoveDataTable = { const spd = target.getStat('spd', false, true); const physical = Math.floor(Math.floor(Math.floor(Math.floor(2 * pokemon.level / 5 + 2) * 90 * atk) / def) / 50); const special = Math.floor(Math.floor(Math.floor(Math.floor(2 * pokemon.level / 5 + 2) * 90 * spa) / spd) / 50); - if (physical > special || (physical === special && this.random(2) === 0)) { + if (physical > special || (physical === special && this.randomChance(1, 2))) { move.category = 'Physical'; move.flags.contact = 1; } diff --git a/data/rulesets.ts b/data/rulesets.ts index 4196b578d0ec..e434c91e491c 100644 --- a/data/rulesets.ts +++ b/data/rulesets.ts @@ -2543,7 +2543,7 @@ export const Rulesets: import('../sim/dex-formats').FormatDataTable = { const spd = target.getStat('spd', false, true); const physical = Math.floor(Math.floor(Math.floor(Math.floor(2 * pokemon.level / 5 + 2) * 90 * atk) / def) / 50); const special = Math.floor(Math.floor(Math.floor(Math.floor(2 * pokemon.level / 5 + 2) * 90 * spa) / spd) / 50); - if (physical > special || (physical === special && this.random(2) === 0)) { + if (physical > special || (physical === special && this.randomChance(1, 2))) { move.category = 'Physical'; move.flags.contact = 1; } diff --git a/sim/prng.ts b/sim/prng.ts index 1ac183d7cf8a..503f75dff6e2 100644 --- a/sim/prng.ts +++ b/sim/prng.ts @@ -82,11 +82,11 @@ export class PRNG { if (from) from = Math.floor(from); if (to) to = Math.floor(to); if (from === undefined) { - return result / 0x100000000; + return result / 2 ** 32; } else if (!to) { - return Math.floor(result * from / 0x100000000); + return Math.floor(result * from / 2 ** 32); } else { - return Math.floor(result * (to - from) / 0x100000000) + from; + return Math.floor(result * (to - from) / 2 ** 32) + from; } } @@ -149,10 +149,10 @@ export class PRNG { return [ 'sodium', // 32 bits each, 128 bits total (16 bytes) - Math.trunc(Math.random() * 0x100000000).toString(16).padStart(8, '0') + - Math.trunc(Math.random() * 0x100000000).toString(16).padStart(8, '0') + - Math.trunc(Math.random() * 0x100000000).toString(16).padStart(8, '0') + - Math.trunc(Math.random() * 0x100000000).toString(16).padStart(8, '0'), + Math.trunc(Math.random() * 2 ** 32).toString(16).padStart(8, '0') + + Math.trunc(Math.random() * 2 ** 32).toString(16).padStart(8, '0') + + Math.trunc(Math.random() * 2 ** 32).toString(16).padStart(8, '0') + + Math.trunc(Math.random() * 2 ** 32).toString(16).padStart(8, '0'), ]; } } @@ -267,10 +267,10 @@ export class Gen5RNG implements RNG { static generateSeed(): Gen5RNGSeed { return [ - Math.trunc(Math.random() * 0x10000), - Math.trunc(Math.random() * 0x10000), - Math.trunc(Math.random() * 0x10000), - Math.trunc(Math.random() * 0x10000), + Math.trunc(Math.random() * 2 ** 16), + Math.trunc(Math.random() * 2 ** 16), + Math.trunc(Math.random() * 2 ** 16), + Math.trunc(Math.random() * 2 ** 16), ]; } } @@ -286,7 +286,7 @@ export type Gen3RNGSeed = ['gen3', number]; export class Gen3RNG implements RNG { seed: number; constructor(seed: Gen3RNGSeed | null = null) { - this.seed = seed ? seed[1] : Math.trunc(Math.random() * 0x100000000); + this.seed = seed ? seed[1] : Math.trunc(Math.random() * 2 ** 32); } getSeed() { return ['gen3', this.seed]; diff --git a/sim/tools/runner.ts b/sim/tools/runner.ts index f10d2fd0765d..11a86680739b 100644 --- a/sim/tools/runner.ts +++ b/sim/tools/runner.ts @@ -140,10 +140,10 @@ export class Runner { // NOTE: advances this.prng's seed by 4. private newSeed(): PRNGSeed { return [ - this.prng.random(0x10000), - this.prng.random(0x10000), - this.prng.random(0x10000), - this.prng.random(0x10000), + this.prng.random(2 ** 16), + this.prng.random(2 ** 16), + this.prng.random(2 ** 16), + this.prng.random(2 ** 16), ]; }