Skip to content

Commit

Permalink
Revert "Implement PRNG peek" By i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyoko-Jeremie committed Sep 10, 2023
1 parent aebe66a commit 554ac30
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
32 changes: 17 additions & 15 deletions src/lib/prngwrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,27 @@ var PRNGWrapper = (() => { // eslint-disable-line no-unused-vars, no-var
*******************************************************************************************************************/
class PRNGWrapper {
constructor(seed, options) {
/* eslint-disable new-cap */
/* Create the Math.seedrandom initialisation to use the state object. */
/* Pass seed through the constructor to return either a copy of itself, or a new generated seed. */
const seeder = new Math.seedrandom(seed, { state : false }, (_, seed) => ({ seed }));
const seeder = new Math.seedrandom(seed, { state: false }, (prng, seed) => ({seed}));
const prngObj = new Math.seedrandom(seeder.seed, options);
/* eslint-disable new-cap */
Object.defineProperties(this, {
_prng : {
value : prngObj
_prng: {
value: prngObj
},
seed : {
writable : true, value : seeder.seed
seed: {
writable: true,
value: seeder.seed
},
pull : {
writable : true, value : 0
pull: {
writable: true,
value: 0
},
state : {
value : prngObj.state
state: {
value: prngObj.state
},
random : {
random: {
value() {
return this._prng();
}
Expand All @@ -52,9 +54,9 @@ var PRNGWrapper = (() => { // eslint-disable-line no-unused-vars, no-var
Old: seed : prng.seed,
pull : prng.pull */
return {
prng : prng.state(),
seed : prng.seed,
pull : prng.pull
prng: prng.state(),
seed: prng.seed,
pull: prng.pull
};
}

Expand All @@ -69,7 +71,7 @@ var PRNGWrapper = (() => { // eslint-disable-line no-unused-vars, no-var
has reached the original pull count.
*/
/* Create new PRNGWrapper with the state object of the old PRNG object. */
const prng = new PRNGWrapper(prngObj.seed, { state : prngObj.state });
const prng = new PRNGWrapper(prngObj.seed, { state: prngObj.state });
prng.pull = prngObj.pull;
return prng;
}
Expand Down
19 changes: 1 addition & 18 deletions src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,22 +658,6 @@ var State = (() => { // eslint-disable-line no-unused-vars, no-var
return _prng ? _prng.state() : null;
}

function prngPeek(count, callback = undefined) {
const values = [];
if (_prng) {
const state = _prng.state();
for (let i = 0; i < count; i++) {
if (typeof callback === 'function') {
values.push(callback(_prng.random()));
} else {
values.push(_prng.random());
}
}
_prng = new PRNGWrapper(_prng.seed, { state: state });
}
return values;
}

function prngRandom() {
if (DEBUG) { console.log('[State/prngRandom()]'); }

Expand Down Expand Up @@ -862,8 +846,7 @@ var State = (() => { // eslint-disable-line no-unused-vars, no-var
isEnabled : { value : prngIsEnabled },
seed : { get : prngSeed },
pull : { get : prngPull },
state : { get : prngState },
peek : { value : prngPeek }
state : { get : prngState }
}))
},
random : { value : prngRandom },
Expand Down

0 comments on commit 554ac30

Please sign in to comment.