How to use xorshift - 10 common examples

To help you get started, we’ve selected a few xorshift 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 beaugunderson / poisson-disc-sampler / test / poisson-disc-sampler.js View on Github external
it('should sample points correctly with a specified RNG', function () {
    var WIDTH = 1000;
    var HEIGHT = 500;

    var xorshift = new XorShift([1, 0, 2, 0]);

    // wrap this because we can't just pass the xorshift.random function to the
    // sampler since it relies on the rest of the object (it calls
    // this.randomint);
    function random() {
      return xorshift.random();
    }

    var sampler = poissonDiscSampler(WIDTH, HEIGHT, 10, random);

    var sample;

    var points = 0;

    while ((sample = sampler())) {
      points++;
github nearform / node-clinic-doctor / test / generate-process-stat.js View on Github external
function generateProcessStat (data, noiseLevel) {
  const rng = new xorshift.constructor([
    294915, 70470, 145110, 287911 // from random.org :)
  ])

  function noise () {
    return rng.random() * noiseLevel
  }

  // flatten data structure
  const flat = {
    delay: data.delay,
    cpu: data.cpu,
    rss: data.memory && data.memory.rss,
    heapTotal: data.memory && data.memory.heapTotal,
    heapUsed: data.memory && data.memory.heapUsed,
    external: data.memory && data.memory.external,
    handles: data.handles && data.handles
github kriskowal / kni / kni.js View on Github external
interactive = false;

        } else if (config.toHtml) {
            makeHtml(states, config.toHtml, {
                title: config.htmlTitle,
                color: config.htmlColor,
                backgroundColor: config.htmlBackgroundColor,
            });
            interactive = false;
        }

        var randomer = xorshift;

        if (config.transcript || config.seed) {
            // I rolled 4d64k this morning.
            randomer = new xorshift.constructor([
                37615 ^ config.seed,
                54552 ^ config.seed,
                59156 ^ config.seed,
                24695 ^ config.seed
            ]);
        }

        if (config.expected) {
            read(config.expected, function onTypescript(err, typescript) {
                if (err) {
                    console.error(err.message);
                    process.exitCode = -1;
                    return;
                }
                test(kniscript, typescript);
            });
github kriskowal / kni / verify.js View on Github external
for (var i = 0; i < story.errors.length; i++) {
            console.error(story.errors[i]);
        }
        return {
            pass: false,
            expected: trans,
            actual: errors,
        };
    }

    var states = story.states;

    // TODO support alternate seeds
    var seed = 0;
    // I rolled 4d64k this morning, for kni.js
    var randomer = new xorshift.constructor([
        37615 ^ seed,
        54552 ^ seed,
        59156 ^ seed,
        24695 ^ seed
    ]);

    var writer = new StringWriter();
    var render = new Console(writer);
    var readline = new FakeReadline(writer, answers);
    var engine = new Engine({
        story: states,
        start: 'start',
        handler: handler,
        render: render,
        dialog: readline,
        randomer: randomer
github nearform / node-cephes / build / generate-c-tester.js View on Github external
#include "mconf.h"
#include "cephes.h"
#include 

int error_code = -1;
int mtherr(char *name, int code) {
  error_code = code;
  return 0;
}

int main() {
`;

const footer = `}\n`;

var rng = new XorShift([
  6724524440630955, 4369800304473057,
  1956920014856890, 8721370862793116
]);

const type2printf = {
  'double': '%.20f',
  'int': '%d'
};

const type2zero = {
  'double': '0.0',
  'int': '0'
};

const argGenerators = {
  double: function () {
github indutny / bn.js / benchmarks / index.js View on Github external
try {
  bignum = require('bignum');
} catch (err) {
  console.log('Load bignum error: ' + err.message.split('\n')[0]);
}
var sjcl = require('eccjs').sjcl.bn;
var bigi = require('bigi');
var BigInteger = require('js-big-integer').BigInteger;
var SilentMattBigInteger = require('biginteger').BigInteger;
var XorShift128Plus = require('xorshift.js').XorShift128Plus;
var benchmarks = [];

var selfOnly = process.env.SELF_ONLY;
var seed = process.env.SEED || crypto.randomBytes(16).toString('hex');
console.log('Seed: ' + seed);
var prng = new XorShift128Plus(seed);

var fixtures = [];
var findex = 0;
function findexRefresh () {
  findex = 0;
}

function add (op, obj) {
  benchmarks.push({
    name: op,
    start: function start () {
      var suite = new benchmark.Suite();

      console.log('Benchmarking: ' + op);

      Object.keys(obj).forEach(function (name) {
github midwayjs / pandora / packages / tracer / src / utils.ts View on Github external
export function getRandom64() {
  let randint = xorshift.randomint();
  let buf = new Buffer(8);
  buf.writeUInt32BE(randint[0], 0);
  buf.writeUInt32BE(randint[1], 4);

  return buf.toString('hex');
}
github midwayjs / pandora / packages / metrics / src / util / TraceUtil.ts View on Github external
export function getRandom64() {
  let randint = xorshift.randomint();
  let buf = new Buffer(8);
  buf.writeUInt32BE(randint[0], 0);
  buf.writeUInt32BE(randint[1], 4);

  return buf.toString('hex');
}
github jaegertracing / jaeger-client-node / src / util.js View on Github external
static getRandom64(): Buffer {
    let randint = xorshift.randomint();
    let buf = this.newBuffer(8);
    buf.writeUInt32BE(randint[0], 0);
    buf.writeUInt32BE(randint[1], 4);
    return buf;
  }
github jaegertracing / jaeger-client-node / src / util.js View on Github external
static getRandom128(): Buffer {
    let randint1 = xorshift.randomint();
    let randint2 = xorshift.randomint();
    let buf = this.newBuffer(16);
    buf.writeUInt32BE(randint1[0], 0);
    buf.writeUInt32BE(randint1[1], 4);
    buf.writeUInt32BE(randint2[0], 8);
    buf.writeUInt32BE(randint2[1], 12);
    return buf;
  }

xorshift

Random number generator using xorshift128+

MIT
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis