Skip to content

Commit

Permalink
fix prng.ts so it works in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
scheibo committed Feb 10, 2025
1 parent 4b244ad commit fc8948f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
2 changes: 2 additions & 0 deletions import
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ const FRAGILE = new Set([
// `sim/dex.ts` has to have its loading reworked to depend on everything up front so that it can
// be used in a browser environment where synchronous `require` and `fs` APIs don't exist.
'sim/dex.ts',
'sim/prng.ts',
'sim/global-types.ts',
'sim/global-variables.d.ts',
]);
Expand Down Expand Up @@ -504,6 +505,7 @@ const SKIP_TESTS = new Set([
'test/sim/state.js',
'test/sim/tools/multi-random-runner.js',
'test/sim/misc/inversebattle.js',
'test/sim/misc/partnersincrime.js',
]);
// Any file that hasn't been 'OVERRIDDEN' we need to copy over from PS
const COPIED = new Set([...FILES].filter(f => !OVERRIDDEN.has(f)));
Expand Down
10 changes: 1 addition & 9 deletions sim/sim/prng.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import {Chacha20} from 'ts-chacha20';
import {Utils} from '../lib/utils';
import * as crypto from 'crypto';

export type PRNGSeed = `${'sodium' | 'gen5' | number},${string}`;
export type SodiumRNGSeed = ['sodium', string];
Expand Down Expand Up @@ -159,7 +158,7 @@ export class PRNG {
}

static generateSeed(): PRNGSeed {
return PRNG.convertSeed(SodiumRNG.generateSeed());
return PRNG.convertSeed(Gen5RNG.generateSeed());
}
static convertSeed(seed: SodiumRNGSeed | Gen5RNGSeed): PRNGSeed {
return seed.join(',') as PRNGSeed;
Expand Down Expand Up @@ -207,13 +206,6 @@ export class SodiumRNG implements RNG {
// reading big-endian
return buf.slice(32, 36).reduce((a, b) => a * 256 + b);
}

static generateSeed(): SodiumRNGSeed {
return [
'sodium',
crypto.randomBytes(16).toString('hex'),
];
}
}

/**
Expand Down

0 comments on commit fc8948f

Please sign in to comment.