How to use seedrandom - 10 common examples

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 tomlarkworthy / animaxe / dist / src / Parameter.js View on Github external
function __export(m) {
    for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
var seedrandom = require("seedrandom");
var OT = require("./frp");
var parametric = require("./parametric");
__export(require("./List"));
exports.DEBUG = false;
var types = require("./types");
__export(require("./types"));
if (exports.DEBUG)
    console.log("Parameter: module loading...");
exports.rndGenerator = seedrandom.xor4096(Math.random() + "");
// Parameter is a transformer from (clock signals -> Value)
/**
 * convert an Rx.Observable into a Parameter by providing an initial value. The Parameter's value will update its value
 * every time and event is received from the Rx source
 */
function updateFrom(initialValue, source) {
    if (exports.DEBUG)
        console.log("updateFrom: build");
    return new OT.SignalFn(function (upstream) {
        if (exports.DEBUG)
            console.log("updateFrom: init");
        var value = initialValue;
        source.subscribe(function (x) { return value = x; });
        return upstream.map(function (_) { return value; });
    });
}
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 stanford-oval / almond-cloud / training / synthetic-gen-process.js View on Github external
async function genBasic(args) {
    const tpClient = new Tp.FileClient({
        locale: args.locale,
        thingpedia: './thingpedia.tt',
        entities: './entities.json',
        dataset: './dataset.tt'
    });
    const schemas = new ThingTalk.SchemaRetriever(tpClient, null, true);

    const rng = seedrandom.alea('almond is awesome');

    const options = {
        thingpediaClient: tpClient,
        schemaRetriever: schemas,

        templateFile: 'index.genie',

        rng: rng,
        locale: args.locale,
        flags: args.flags || {},
        maxDepth: args.maxdepth,
        targetPruningSize: args.target_pruning_size,
        debug: false, // no debugging, ever, because debugging also goes to stdout
    };

    const generator = new Genie.BasicSentenceGenerator(options);
github nearform / node-hidden-markov-model-tf / lib / hmm.js View on Github external
function randomUniform (shape, dtype, seed) {
  // This is how randomNormal handles the seed input
  // SEE: https://github.com/tensorflow/tfjs-core/blob/v0.12.0/src/ops/rand.ts
  const seedValue = seed || Math.random();
  const random = seedrandom.alea(seedValue.toString());
  return tf.rand(shape, random, dtype);
}
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 stanford-oval / thingtalk / test / test_sentence_generator_manual.js View on Github external
});
    parser.addArgument('--maxdepth', {
        type: Number,
        defaultValue: 6,
        help: 'Maximum depth of synthetic sentence generation',
    });
    parser.addArgument('--turking', {
        nargs: 0,
        action: 'storeTrue',
        help: 'Restrict grammar rules to MTurk-friendly ones.',
        defaultValue: false
    });

    const args = parser.parseArgs();
    const options = {
        rng: seedrandom.alea('almond is awesome'),
        language: 'en',
        targetLanguage: 'thingtalk',
        thingpediaClient: _tpClient,
        turkingMode: args.turking,
        maxDepth: args.maxdepth,
        debug: true
    };

    const generator = new SentenceGenerator(options);
    const transform = new stream.Transform({
        writableObjectMode: true,

        transform(ex, encoding, callback) {
            callback(null, ex.id + '\t' + ex.utterance + '\t' + ex.target_code + '\n');
        },
github stanford-oval / thingtalk / test / test_sentence_generator.js View on Github external
async function main() {
    const options = {
        rng: seedrandom.alea('almond is awesome'),
        language: 'en',
        targetLanguage: 'thingtalk',
        thingpediaClient: _tpClient,
        turkingMode: false,
        maxDepth: 7,
        debug: true
    };

    const generator = new SentenceGenerator(options);
    const writer = new stream.Writable({
        objectMode: true,

        write(ex, encoding, callback) {
            Promise.resolve().then(() => {
                return processOne(ex.id, ex.utterance, ex.target_code);
            }).then(() => {

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