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 🙏

© 2025 – Pkg Stats / Ryan Hefner

js-randomness-predictor-cpp

v1.1.0

Published

Node.js native addon (C++) for high-performance Math.random() prediction

Downloads

94

Readme

js-randomness-predictor-cpp

npm version

Node.js native addon (C++) for high-performance Math.random() prediction in V8 (Node), Chrome, and Firefox

Installation

Use your favorite package manager.

npm i js-randomness-predictor-cpp
yarn add js-randomness-predictor-cpp
pnpm add js-randomness-predictor-cpp
# etc...

Usage

IMPORTANT:

  • You must use the appropriate predictor for the environment used to generate the initial sequence. Meaning, if you generated the sequence in Chrome, you must use the Chrome predictor, etc..
  • We recommend at least 4 numbers in the initial sequence.
// ESM
import JSRandomnessPredictorCpp from "js-randomness-predictor-cpp";
// CJS
const JSRandomnessPredictorCpp = require("js-randomness-predictor-cpp");

Chrome Predictor

const chromePredictor = JSRandomnessPredictorCpp.chrome([...]);
const nextPrediction = chromePredictor.predictNext();
// You'll need to manually verify accuracy.

Firefox Predictor

const firefoxPredictor = JSRandomnessPredictorCpp.firefox([...]);
const nextPrediction = firefoxPredictor.predictNext();
// You'll need to manually verify accuracy.

FIREFOX ISSUE WHEN GENERATING NUMBERS IN CONSOLE

You must disable "Instant Evaluation", otherwise your predictions may show incorrectly. Especially if you use more than one call to generate the initial sequence + expected values.

If you do not want to disable "Instant Evaluation", you'll need to generate initial sequence + expected values in one command.

So instead of using two (or more) calls to Math.random:

/** Pretend this is the console */
// Output used as initial sequence.
Array.from({ length: 4 }, Math.random);
// Output used for validating predictions.
Array.from({ length: 10 }, Math.random);

You'll need to do:

/** Pretend this is the console */
// Only use one call! Manually separate numbers!
Array.from({ length: 6 }, Math.random);
[
  // --------------------|
  0.5654163987207667, // |
  0.7409356182179403, // | --> Use "these" numbers as initial sequence
  0.46136469064448193, //|
  0.18124646315195891, //|
  // --------------------|
  0.25678544986069995, // --> Use the rest of the numbers for validation
  0.5543550504255771,
];

Node/V8 Predictor

Since we are running in V8, we can produce the initial sequence dynamically by not providing any parameters to the v8() method. This will automatically generate a sequence behind the scenes.

Keep in mind, you can manually provide a sequence as well.

Node/V8 : Provide Your Own Sequence

const manualSequence = Array.from({ length: 4 }, Math.random);
// You could also generate your sequence via Node REPL and provide it that way.
const manualSequence = [
  /* copy/paste numbers generated via REPL */
];
const v8Predictor = JSRandomnessPredictorCpp.v8(manualSequence);
const nextPrediction = v8Predictor.predictNext();
// We can programmatically verify since we are running in Node.
const isAccurate = nextPrediction === Math.random();

Node/V8 : Automatically Generate Sequence

// Automatically create sequence behind the scenes because
// parameter not provided to 'v8' method.
const v8Predictor = JSRandomnessPredictorCpp.v8();
const nextPrediction = v8Predictor.predictNext();
// We can programmatically verify since we are running in Node.
const isAccurate = nextPrediction === Math.random();