{"name":"pure-rand","version":"3.0.0-alpha.2.0.0.2","description":" Pure random number generator written in TypeScript","type":"commonjs","main":"lib/pure-rand.js","exports":{".":{"require":"./lib/pure-rand.js","default":"./lib/esm/pure-rand.js"}},"module":"lib/esm/pure-rand.js","types":"lib/types/pure-rand.d.ts","sideEffects":false,"scripts":{"format:check":"prettier --list-different \"**/*.{js,ts}\"","format:fix":"prettier --write \"**/*.{js,ts}\"","build":"tsc && tsc -p ./tsconfig.declaration.json","build:esm":"tsc --module es2015 --outDir lib/esm --moduleResolution node && cp package.esm-template.json lib/esm/package.json","build:prod":"npm run build && npm run build:esm && node postbuild/main.cjs","test":"jest --config jest.config.cjs --coverage","coverage":"cat ./coverage/lcov.info | coveralls","build:bench:old":"tsc --target es6","build:bench:new":"tsc --target es6 --outDir lib-new/","auto:bench":"git stash && npm run build:bench:old && git stash pop && npm run build:bench:new && node perf/benchmark.js"},"repository":{"type":"git","url":"git+https://github.com/dubzzz/pure-rand.git"},"author":{"name":"Nicolas DUBIEN","email":"github@dubien.org"},"license":"MIT","bugs":{"url":"https://github.com/dubzzz/pure-rand/issues"},"homepage":"https://github.com/dubzzz/pure-rand#readme","dependencies":{},"devDependencies":{"@types/jest":"^24.9.0","@types/node":"^13.1.8","benchmark":"^2.1.4","coveralls":"^3.0.9","fast-check":"^1.21.0","glob":"^7.1.6","jest":"^25.2.7","prettier":"1.16.4","replace-in-file":"^5.0.2","source-map-support":"^0.5.16","ts-jest":"^25.3.1","typescript":"^3.7.5"},"keywords":["pure random","random number generator"],"gitHead":"d6bb7c841052798a89b0b86e1172280928d0972a","readme":"# pure-rand\n#### Pure random number generator written in TypeScript\n\n[![Build Status](https://travis-ci.org/dubzzz/pure-rand.svg?branch=master)](https://travis-ci.org/dubzzz/pure-rand)\n[![npm version](https://badge.fury.io/js/pure-rand.svg)](https://badge.fury.io/js/pure-rand)\n[![dependencies Status](https://david-dm.org/dubzzz/pure-rand/status.svg)](https://david-dm.org/dubzzz/pure-rand)\n[![devDependencies Status](https://david-dm.org/dubzzz/pure-rand/dev-status.svg)](https://david-dm.org/dubzzz/pure-rand?type=dev)\n\n[![Coverage Status](https://coveralls.io/repos/github/dubzzz/pure-rand/badge.svg)](https://coveralls.io/github/dubzzz/pure-rand)\n[![Maintainability](https://api.codeclimate.com/v1/badges/7cb8cb395740446a3108/maintainability)](https://codeclimate.com/github/dubzzz/pure-rand/maintainability)\n\n## Getting started\n\n### In node\n\nInstall the module with: `npm install pure-rand`\n\nUnlike classical random number generators, `pure-rand` comes with a set of *pure* and *seeded* generators (implementing the interface [RandomGenerator](https://github.com/dubzzz/pure-rand/blob/master/src/generator/RandomGenerator.ts)).\nEach time a call to `.next()` method is done, the generator provides both the generated value and the next generator.\n\nAs a consequence, a given generator will always produce the same value. It can be called as many times as required without impacting its state. This ability makes it easier to replay code section relying on random without having to re-seed a new generator and replay the whole path to be in the same state.\n\n### In a web-page\n\nIn order to use `pure-rand` from a web-page, you have to reference the web-aware script as follow:\n\n```html\n<script type=\"module\">\n   import * as prand from \"https://unpkg.com/pure-rand/lib/esm/pure-rand.js\";\n   // prand is now available\n</script>\n```\n\nYou can also reference a precise version by setting the version you want in the url:\n\n```html\n<script type=\"module\">\n   import * as prand from \"https://unpkg.com/pure-rand@1.2.0/lib/esm/pure-rand.js\";\n   // prand is now available\n</script>\n```\n\n## Usage\n\n```javascript\nimport prand from 'pure-rand'\n\nconst seed = 42;\n\n// Instanciates a Mersenne Twister\n// random number generator with the seed=42\nconst gen1 = prand.mersenne(seed);\n\n// Build a random value `n` and the next generator `gen2`\n// the random value `n` is within the range:\n// gen1.min() (included) to gen1.max() (included)\nconst [n, gen2] = gen1.next();\n// Calling again next on gen1 will provide the very same output:\n// `n: number` and `gen2: RandomGenerator`\n\n// In order to generate values within range,\n// distributions are provided by the pure-rand\n\n// Like `.next()` method,\n// distributions take an incoming generator and extract a couple:\n// (n: number, nextGenerator: RandomGenerator)\n\n// The distribution built by the call to prand.uniformIntDistribution(0, 9)\n// generates uniformly integers within 0 (included) and 9 (included)\nconst [nRange, gen3] = prand.uniformIntDistribution(0, 9)(gen1);\n// Calling again the same Distribution with the same RandomGenerator\n// will provide the same output\n\n// Whenever you want to use the distribution only once you can directly call\n// prand.uniformIntDistribution(from, to, rng) which is totally equivalent to prand.uniformIntDistribution(from, to)(rng)\n// In terms of performances, the 3 parameters version is faster\nconst [nNoDistributionInstance, gen4] = prand.uniformIntDistribution(0, 9, gen3);\n\n// Some generators come with built-in jump\n// jump provides the ability to skip a very large number of intermediate values\n// Calling jump is recommended whenever you want to build non-overlapping subsequences\nconst gen4 = prand.xoroshiro128plus(seed);\nconst offsetGen4 = gen4.jump();\n// In the case of:\n// - xoroshiro128plus - jump is equivalent to 2^64 calls to next\n// - xorshift128plus  - jump is equivalent to 2^64 calls to next\n```\n\nModule import can also be done using one of the following syntaxes:\n\n```javascript\nimport * as prand from 'pure-rand';\nimport { mersenne } from 'pure-rand';\nconst prand = require('pure-rand');\nconst { mersenne } = require('pure-rand');\n```\n\n## Documentation\n\n### Random number generators\n\nAll the [RandomGenerator](https://github.com/dubzzz/pure-rand/blob/master/src/generator/) provided by `pure-rand` derive from the interface [RandomGenerator](https://github.com/dubzzz/pure-rand/blob/master/src/generator/RandomGenerator.ts) and are pure and seeded as described above.\n\nThe following generators are available:\n- `prand.xorshift128plus(seed: number)`: xorshift128+ generator whose values are within the range -0x80000000 to 0x7fffffff\n- `prand.xoroshiro128plus(seed: number)`: xoroshiro128+ generator whose values are within the range -0x80000000 to 0x7fffffff\n- `prand.mersenne(seed: number)`: Mersenne Twister generator whose values are within the range 0 to 0xffffffff\n- `prand.congruential(seed: number)`: Linear Congruential generator whose values are within the range 0 to 0x7fff\n- `prand.congruential32(seed: number)`: Linear Congruential generator whose values are within the range 0 to 0xffffffff\n\nSome helpers are also provided in order to ease the use of `RandomGenerator` instances:\n- `prand.generateN(rng: RandomGenerator, num: number): [number[], RandomGenerator]`: generates `num` random values using `rng` and return the next `RandomGenerator`\n- `prand.skipN(rng: RandomGenerator, num: number): RandomGenerator`: skips `num` random values and return the next `RandomGenerator`\n\n### Distributions\n\nAll the [Distribution](https://github.com/dubzzz/pure-rand/tree/master/src/distribution) take a `RandomGenerator` as input and produce a couple `(n: number, nextGenerator: RandomGenerator)`. A `Distribution` is defined as `type Distribution<T> = (rng: RandomGenerator) => [T, RandomGenerator];`.\n\nFor the moment, available `Distribution` are:\n- `prand.uniformIntDistribution(from: number, to: number): Distribution<number>`\n- `prand.uniformBigIntDistribution(from: bigint, to: bigint): Distribution<bigint>`*\n\n\\*Requires your JavaScript interpreter to support bigint\n","readmeFilename":"README.md","_id":"pure-rand@3.0.0-alpha.2.0.0.2","_nodeVersion":"12.16.1","_npmVersion":"6.13.4","dist":{"integrity":"sha512-QyV9El0uy2aqqVsEmPoNSIsvl1jbytTRtLR5JPH7h+mKJ9GMu7kHPJJRykVD/+L9uDPIlcHJxDuDozsJqJs7lg==","shasum":"4e701ff3d43384aa7a57cf2d3f580e44f6cd65aa","tarball":"http://registry-npm.ywwl.com/pure-rand/download/pure-rand-3.0.0-alpha.2.0.0.2.tgz","fileCount":48,"unpackedSize":47735,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeia65CRA9TVsSAnZWagAAbAQQAIutCRF04BiuAFdeztWi\ngS1PKPnxWdM4zCqk2hGy6/iEkcI/mBQBNUSDi5DwN+P3dMVLD4qFnrc/LFfn\noqivnw2+KP7A1GeO+Na+WJs9qQOC2u8zcn0lnPmJdDInfNjkVUJOuI5ocziN\npmWJYeO8AuOeWBt+/Ej0xfQnlxAnPCcp4+ZGQRPn3naH5yZ7Sf1EUkyqDQOO\nGOvdEEPmguGhBstnM38/bL3G/iehenyw5fDXVXq7A84DvsgVygC9LleDSw+e\nALzsHIaTSlnOhfIGe3QZpjErKjXTDm9CbdDlEHAAj7VSRP7G0YcWBl3PqxpH\n/glSGtEFe48tHTW/97NCK6CDNJfxmCYMyH4PoP4GsuDbpLfxITfU3VZSFkoG\nTM1O6FmCxml5lSuXo/b7o2J7A7pH5u5biAMHA3cXxQODeXabOO0r3ku8YKOY\nBww8mQZAI8VvAwI3WoUjSpzGN3otAh0/b9KkOwZeNLo/ccCRdLSYIllehAOp\nrxL13qeG2u/v8sggOPYkhB6VIJfvIu+793lz9TeeNWnSLVGGRzz7ahELMpAm\nu/c1TgxRRqNdO/GrhWV11gWB5Uq0K+f28XXDwQxxW62AzoNWUEZ8cSXyPj0j\nYIy/juKy7oqQiancKEtvLIFf9wwhg9CAegyjPZY20qiXYNQnnJejZryz9qyK\nxSly\r\n=YFRW\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDu69fVvXHIyOU+GLsVoprWwoO6rH2MQ8mSVG1+dPZRUgIgCvae0LbMXYJlbERDVvlmTM0IhNUx7W3b5S9HloUPbGo="}],"size":11794,"noattachment":false,"key":"/pure-rand/-/pure-rand-3.0.0-alpha.2.0.0.2.tgz"},"maintainers":[{"name":"ndubien","email":"npm@dubien.org"}],"_npmUser":{"name":"ndubien","email":"npm@dubien.org"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/pure-rand_3.0.0-alpha.2.0.0.2_1586081465047_0.730356720142292"},"_hasShrinkwrap":false,"publish_time":1586081465249,"_cnpm_publish_time":1586081465249,"dist-tags":{"experimental":"5.0.0-experimental.4.2.1.0","latest":"8.4.2","next":"3.0.0-alpha.2.0.0.2"}}