npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mangata-prng-xoshiro

v3.0.0

Published

JavaScript implementation of the xoshiro deterministic family of PRNGs (pseudorandom number generators). Written in pure JS, and works on node.js as well as browsers.

Downloads

14

Readme

Mangata Fork

This fork is for cases where we want to export multiple module types. Fork will expose CJS and ESM module formats. This way we user can use older versions of NodeJS to import CJS build or newer NodeJS versions to import ESM. When this fork is used in the browser, users can use the ESM build. Also we fixed the issue where different implementations of xoshiro with the same seed gave us different result.

CREDIT

This package was created and implemented by Khang Le. Here is the link to original package repo: prng-xoshiro

Installation

Install by running yarn add mangata-prng-xoshiro

xoshiro library

A pure Javascript implementation of the xoshiro family of PRNGs. Since it is implemented in vanilla JS, it can be run in a <script> tag, or even in the browser console. In fact, the xoshiro128 bundle can even run on browsers that implement only up to ES5.

PRNG results are fully deteministic and reproducible when provided with a seed.

browsers

The dist folder contains pre-built bundles that expose the library as a global variable named XoShiRo. There are 3 different bundles:

  • xoshiro.js includes the entire library.
  • xoshiro256.js includes only the xoshiro256 generators. BigInt (formally added in ECMAScript 2020) must be supported to run it.
  • xoshiro128.js includes only the xoshiro128 generators. This file is ES5-compatible.

The src source code folder contains ES6 modules that are fully browser-compatible as well and could be used with <script type="module">.

API

The available generators are XoShiRo256PlusPlus, XoShiRo256StarStar, XoShiRo256Plus, XoShiRo128PlusPlus, XoShiRo128StarStar, XoShiRo128Plus. For more information, see the website on xoshiro.

All generators implement the Iterable Interface, so it is possible to use with for...of loops:

for (const rn of new XoShiRo256PlusPlus()) {
	// Infinite unless broken out of
}

In the following, generator refers to any generator, while generator128 refers to only xoshiro128 generators and generator256 refers to only xoshiro256 generators.

new generator()

Creates and seeds a generator with a seed. It is not suggested to use this method if you would like reproducible results, and generators created this way will not be guaranteed to be seeded with the same values in future versions of this library.

new generator256(seed)

Creates a new generator. seed will be used to seed a splitMix64 generator, whose output will in turn be used to seed this generator. This method is only available for the xoshiro256 generators.

  • For the xoshiro256 generators, seed must be a BigInt.

new generator128(seedLo, seedHi)

Creates a new generator. seedLo and seedHi are two Numbers that represent least and most significant bits of a 64-bit integer, respectively. They will be used to seed a splitMix64 generator, whose output will in turn be used to seed this generator. This method is only available for the xoshiro128 generators.

  • For the xoshiro128 generators, seed must be a Number.

new generator(s0, s1, s2, s3)

Creates a generator and sets the state to the the variables given.

  • For the xoshiro256 generators, all parameters are BigInts.
  • For the xoshiro128 generators, all parameters are Numbers.

generator256.nextBigInt(n)

Returns a random BigInt in the range 0 to n (exclusive). If n is not provided, it defaults to 0xFFFFFFFFFFFFFFFFn.

generator128.nextNumber(n)

Returns a random number in the range 0 to n (exclusive). If n is not provided, it defaults to 0xFFFFFFFF.

generator.peek()

Returns the next random number (as if calling nextBigInt or nextNumber without parameters) without altering the state of the generator.

generator.jump()

Advances the generator's state. This is equivalent to 2^64 calls to next() for xoshiro128 generators, and 2^128 calls for xoshiro256 generators.

generator.longJump()

Advances the generator's state. This is equivalent to 2^96 calls to next() for xoshiro128 generators, and 2^192 calls for xoshiro256 generators.

Contributing

First clone the repository:

git clone https://gitgud.io/anglekh/prng-xoshiro.git

Then install dependencies with npm install.

This library uses Jest for testing. Run npm test before committing to run the tests.

Build using npm run build. The output will appear in the default webpack directory, dist.