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

multi-random

v0.2.1

Published

Provides random using several random generators: JS default Math.random(), Quantum random and RandomOrg random

Downloads

2

Readme

Node MultiRandom generator

Descrtiption

This module allows to use different random generators in easy way. This can be used as just a wrapper for default Pseudo-Random generator in javascript allowing you to set maximum and minimum values to return random value.

Check module on NPMjs

Install

npm install multi-random

Usage

const MultiRandom = require('multi-random');

// Create object
let randGen = new MultiRandom({
  'plugin': 'math-random', // Driver to use. Defaults to math-random
  'pluginOptions': {}, // Options passed to plugin. Can be different for different plugins
  'blockingRand': false, // If set to true this means that calling randGen.random(min, max)  will block process until it is ready to return numbers
  'supportFallback': true // If set to true, it will return data using Pseudo-Random generator Math.Random() if external data pool is not yet filled. This has no effect on math-random driver at all.
});

// Generate random number between 6 and 256
// Note: values below zero or floating values are not yet supported.
randGen.random(6, 256);

// Note: Creating MultiRandom object with SAME settings will use same pool for RandomOrg driver. See example below.

Example of using Random-Org to transparently get random values

In order to see a lot of debug information, please add DEBUG="multi-random" to your ENV variables.

const MultiRandom = require('multi-random');

let prandom = new MultiRandom(); // This will use default Math.random()
let trandom = new MultiRandom({ // Creating Random-Org driver with custom pool size 
  'plugin': 'random-org',
  'pluginOptions': {
    poolSize: 128,
  }
});

let trandom2 = new MultiRandom({ // One more random generator using Random-Org values
  'plugin': 'random-org',
});

// Printing first random. It will be swapned from Math.random() because
// pool of random data is empty so it uses Math.random() as fallback.
// If you are aware of having ONLY true random numbers set supportFallback to false
// And it won't permit to get random number if pool is empty and an error will be thrown.
console.log('First random is: ' + trandom.random(128, 512));

// Wait 10 seconds (the pool must be filled already).
setTimeout(function() {
  for (let i=0; i<256; i++) {
    let min = prandom.random(0, 256); // We dont spend RandomOrg data here. Use wrapper for default Math.random()
    let max = prandom.random(257, 65535);

    // Example of creating new object with SAME settings as trandom created before.
    // It WON'T fill pool again because it is already filled by first call with same parameters.
    let trandom = new MultiRandom({
      'plugin': 'random-org',
      'pluginOptions': {
        poolSize: 128,
      }
    });
    console.log('Random between ' + min + ' and ' + max + ': ' + trandom.random(min, max));
  }
}, 10000);

Bugs, support, disclaimer

Please, feel free to create issues via github and describe faced problems or suggest ideas. I am not node js developer and this is my first module, I might not be experienced in node js programming but I'm experienced in web development and in development on PHP so every comment will be useful for me.