source: trip-planner-front/node_modules/core-js/modules/esnext.math.seeded-prng.js@ b738035

Last change on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1var $ = require('../internals/export');
2var anObject = require('../internals/an-object');
3var numberIsFinite = require('../internals/number-is-finite');
4var createIteratorConstructor = require('../internals/create-iterator-constructor');
5var InternalStateModule = require('../internals/internal-state');
6
7var SEEDED_RANDOM = 'Seeded Random';
8var SEEDED_RANDOM_GENERATOR = SEEDED_RANDOM + ' Generator';
9var setInternalState = InternalStateModule.set;
10var getInternalState = InternalStateModule.getterFor(SEEDED_RANDOM_GENERATOR);
11var SEED_TYPE_ERROR = 'Math.seededPRNG() argument should have a "seed" field with a finite value.';
12
13var $SeededRandomGenerator = createIteratorConstructor(function SeededRandomGenerator(seed) {
14 setInternalState(this, {
15 type: SEEDED_RANDOM_GENERATOR,
16 seed: seed % 2147483647
17 });
18}, SEEDED_RANDOM, function next() {
19 var state = getInternalState(this);
20 var seed = state.seed = (state.seed * 1103515245 + 12345) % 2147483647;
21 return { value: (seed & 1073741823) / 1073741823, done: false };
22});
23
24// `Math.seededPRNG` method
25// https://github.com/tc39/proposal-seeded-random
26// based on https://github.com/tc39/proposal-seeded-random/blob/78b8258835b57fc2100d076151ab506bc3202ae6/demo.html
27$({ target: 'Math', stat: true, forced: true }, {
28 seededPRNG: function seededPRNG(it) {
29 var seed = anObject(it).seed;
30 if (!numberIsFinite(seed)) throw TypeError(SEED_TYPE_ERROR);
31 return new $SeededRandomGenerator(seed);
32 }
33});
Note: See TracBrowser for help on using the repository browser.