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

park-miller-carta-prng

v0.1.4

Published

An efficient Pseudo-Random Number Generator

Downloads

7

Readme

Park-Miller-Carta PRNG

(documentation in progress) This is a multi-language repository, demonstrating C-Rust-Node.js-Web interoperability/portability.

It utilizes Rust as a build system, in order to compile the original C implemetations by Robin Whittle. A faithful Rust port is also included, cross-compilable to asm.js and WebAssembly via Emscripten, for use in Node.js and browsers.

Using from browser

Add with npm i --save --only=production park-miller-carta-prng.

index.html:

<!DOCTYPE html>
<html>
<head>
  <title>Wasm</title>
</head>
<body>

<script type="text/javascript">
  var Module = {};

  var prng = {
    seed: (i) => Module.prng_new(i),
    destroy: (ptr) => Module.prng_destroy(ptr),
    getInteger: (ptr) => Module.next_unsigned_integer(ptr),
    getFloat: (ptr) => Module.next_unsigned_float(ptr)
  };

  function fetchAndInstantiate(url, importObject) {
    return fetch(url).then(response =>
      response.arrayBuffer()
    ).then(bytes =>
      WebAssembly.instantiate(bytes, importObject)
    ).then(results =>
      results.instance
    );
  }

  fetchAndInstantiate('node_modules/park-miller-carta-prng/dist/wasm/browser-standalone.wasm', {})
  .then( mod => {
    Module.prng_new = mod.exports.prng_new;
    Module.prng_destroy = mod.exports.prng_destroy;
    Module.next_unsigned_integer = mod.exports.next_unsigned_integer;
    Module.next_unsigned_float = mod.exports.next_unsigned_float;
  })
  .then( () => {
    var ptr = prng.seed(1);
    var container = document.createElement('div');
    container.textContent = `integer: ${prng.getInteger(ptr)} float: ${prng.getFloat(ptr)}`
    document.body.appendChild(container);
    prng.destroy(ptr);
  });

</script>
</body>
</html>

host the html via python2 -m SimpleHTTPServer/python3 -m http.server of your preferred method.

Using from Node.js

WebAssembly & asm.js

Add with npm i --save --only=production park-miller-carta-prng.

index.js:

let {prng, asmjs, wasm} = require("park-miller-carta-prng");
let assert = require('assert');

// use asm.js version
let generator = prng(asmjs)(1);

assert(generator.getInteger() === 16807);
generator.destroy();

// use wasm version
generator = prng(wasm)(1);

assert(generator.getInteger() === 16807);
generator.destroy();

You should always call destroy() when you are done using the generator. Available methods:

  • prng, takes either the supplied asmjs, or wasm modules, generated by emcc. Then, it must be supplied with a positive seed integer.
  • getInteger, getFloat and destroy methods, are self explanatory.

Native Addon

Clone the repository and npm run build:addon. check src/test.coffee for usage. [Todo] simple API, conditional build on npm download.

Using from Rust

Add park-miller-carta-prng to [dependencies] in Cargo.toml

main.rs:

extern crate prng;
use prng::PRNG;

fn main() {
    let mut prng = PRNG::new(1);
    let random_float = prng.next_unsigned_float();
    assert_eq!(0.000007826369, random_float);

    let random_int = prng.next_unsigned_integer();
    assert_eq!(282475249, random_int);
}

Getting Started

  1. Clone the repository: git clone https://github.com/kenOfYugen/park-miller-carta-prng
  2. Enter the directory: cd park-miller-carta-prng
  3. Build (add the --release flag for optimized builds)
  • Rust-C static/dynamic libraries: cargo b
  • asm.js library: cargo b --target asmjs-unknown-emscripten
  • wasm library: cargo b --target wasm32-unknown-emscripten
  • standalone wasm library: cargo b --target wasm32-unknown-unknown
  • Node.js: npm i && npm run build:all

Prerequisites

  • Rust, get it via rustup.
  • Node.js for running asm.js/wasm.
  • emsdk, for compilation to asm.js/wasm.

Checklist

  • [x] Rust API
  • [x] C API
  • [x] Node.js asm.js/wasm via emscripten
  • [x] Node.js native Addon
  • [ ] Browser asm.js/wasm via emscripten
  • [x] wasm via --target wasm32-unknown-unknown