How to use the seedrandom function in seedrandom

To help you get started, we’ve selected a few seedrandom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github qrohlf / trianglify / src / trianglify.js View on Github external
export default function trianglify (_opts) {
  const opts = {...defaultOptions, ..._opts}

  // standard randomizer, used for point gen and layout
  const rand = seedrandom(opts.seed)

  const randomFromPalette = () => {
    if (opts.palette instanceof Array) {
      return opts.palette[Math.floor(rand()*opts.palette.length)]
    }
    const keys = Object.keys(opts.palette);
    return opts.palette[keys[Math.floor(rand()*keys.length)]]
  }

  // The first step here is to set up our color scales for the X and Y axis.
  // First, munge the shortcut options like 'random' or 'match' into real color
  // arrays. Then, set up a Chroma scale in the appropriate color space.
  const processColorOpts = (colorOpt) => {
    switch (true) {
      case Array.isArray(colorOpt):
        return colorOpt
github facebook / prepack / src / intrinsics / ecma262 / Date.js View on Github external
function getCurrentTime(): AbstractValue | NumberValue {
    if (realm.useAbstractInterpretation) {
      return AbstractValue.createTemporalFromTemplate(realm, buildDateNowSrc, NumberValue, [], {
        isPure: true,
        skipInvariant: true,
      });
    } else {
      let newNow = Date.now();
      if (realm.strictlyMonotonicDateNow && lastNow >= newNow) {
        if (!offsetGenerator) offsetGenerator = seedrandom(0);
        // certain behaviors in the test262 test suite can only be (reliably) triggered if Date.now() is strictly monotonically increasing
        // TODO #1004: Set the strictlyMonotonicDateNow option on the realm in the test262 test runner, fix the issues that will come up in the tests, and remove this comment.
        newNow = lastNow + 1 + Math.floor(offsetGenerator() * 500);
      }
      lastNow = newNow;
      return new NumberValue(realm, newNow);
    }
  }
github chrisrzhou / react-wordcloud / src / index.tsx View on Github external
fontStyle,
        fontSizes,
        fontWeight,
        padding,
        rotations,
        rotationAngles,
        spiral,
        scale,
      } = mergedOptions;

      const sortedWords = words
        .concat()
        .sort((x, y) => descending(x.value, y.value))
        .slice(0, maxWords);

      const random = deterministic ? seedrandom('deterministic') : seedrandom();

      const layout = cloud()
        .size(size)
        .padding(padding)
        .words(sortedWords)
        .rotate(() => {
          if (rotations === undefined) {
            // default rotation algorithm
            return (~~(random() * 6) - 3) * 30;
          } else {
            return rotate(rotations, rotationAngles, random);
          }
        })
        .spiral(spiral)
        .random(random)
        .text(getText)
github huy-nguyen / squarify / src / __tests__ / index.js View on Github external
test('Should not cause stack overflow for large input', () => {
  const randomNumberGenerator = randomLogNormal.source(seedRandom('abc'))();
  const size = 10000;
  const data  = [];
  for (let i = 0; i < size; i += 1) {
    const datum = {
      value: Math.ceil(randomNumberGenerator() * 10000),
    };
    data.push(datum);
  }


  expect(() => entry(data, {x0: 0, y0: 0, x1: 1000, y1: 1000})).not.toThrow();
});
github Yomguithereal / talisman / test / helpers / random.js View on Github external
const rng = () => {
  return seedrandom('shawarma');
};
github airbnb / react-sketchapp / src / jsonUtils / models.ts View on Github external
function e7(seed?: string) {
  const random = seed ? seedrandom(`${seed}0`) : Math.random;
  const d0 = (random() * 0xffffffff) | 0;
  const d1 = (random() * 0xffffffff) | 0;
  const d2 = (random() * 0xffffffff) | 0;
  const d3 = (random() * 0xffffffff) | 0;
  return `${lut[d0 & 0xff] +
    lut[(d0 >> 8) & 0xff] +
    lut[(d0 >> 16) & 0xff] +
    lut[(d0 >> 24) & 0xff]}-${lut[d1 & 0xff]}${lut[(d1 >> 8) & 0xff]}-${
    lut[((d1 >> 16) & 0x0f) | 0x40]
  }${lut[(d1 >> 24) & 0xff]}-${lut[(d2 & 0x3f) | 0x80]}${lut[(d2 >> 8) & 0xff]}-${
    lut[(d2 >> 16) & 0xff]
  }${lut[(d2 >> 24) & 0xff]}${lut[d3 & 0xff]}${lut[(d3 >> 8) & 0xff]}${lut[(d3 >> 16) & 0xff]}${
    lut[(d3 >> 24) & 0xff]
  }`;
}
github pinda-fun / pinda-fun / Web / src / components / games / PandaSequence / SequenceGenerator.ts View on Github external
export function* randomWithinBounds(
  lowerBound: number,
  upperBound: number,
  seed: string = Date.now().toLocaleString(),
): Generator {
  const random = seedrandom(seed);
  while (true) yield Math.floor(random() * (upperBound - lowerBound) + lowerBound);
}
github boxart / boxart-boiler / src / util / rng.js View on Github external
function _rng(state = {}, handler = gen => gen()) {
  const seed = state.seed;
  const options = {
    state: state.arc || {},
  };

  const result = seedrandom(seed, options);

  return {
    number: handler(result),
    state: {
      seed,
      arc: result.state(),
      count: (state.count || 0) + 1,
    },
  };
}
github kiali / kiali / vendor / github.com / kiali / k-charted / web / pf4 / src / types / __mocks__ / Dashboards.mock.ts View on Github external
export const generateRandomDashboard = (title: string, seed?: string): DashboardModel => {
  if (seed) {
    seedrandom(seed, { global: true });
  }
  return {
    title: title,
    charts: [
      generateRandomMetricChart('Single metric', ['chocolate'], 4),
      generateRandomMetricChartWithLabels('Single metric with labels', [
        genLabels('apples', undefined, [['color', 'green'], ['size', 'big']])
      ], 4),
      generateRandomHistogramChart('Histogram', 4),
      generateRandomMetricChart('Several metrics', ['dogs', 'cats', 'birds'], 6),
      generateRandomMetricChartWithLabels('Several metrics with labels', [
        genLabels('apples', undefined, [['color', 'green'], ['size', 'big']]),
        genLabels('oranges', undefined, [['color', 'orange'], ['size', 'small']]),
        genLabels('bananas', undefined, [['color', 'yellow'], ['size', 'medium']])
      ], 6),
      { name: 'empty 1', unit: 'bytes', spans: 6, metrics: [] },

seedrandom

Seeded random number generator for Javascript.

MIT
Latest version published 5 years ago

Package Health Score

70 / 100
Full package analysis

Popular seedrandom functions