o2.random

o2.js — A utility to generate random hex strings with various cryptographical strength. — http://o2js.com/.

Usage no npm install needed!

<script type="module">
  import o2Random from 'https://cdn.skypack.dev/o2.random';
</script>

README

        ___       _
  ____ |__ \     (_)____
 / __ \__/ /    / / ___/
/ /_/ / __/_   / (__  )    A Coherent Solution
\____/____(_)_/ /____/  to Your JavaScript Dilemma ;)
           /___/

o2.random (v.0.1.4)

A utility to generate random hex strings with various cryptographical strength.

o2.random uses callbacks, and does not block the program execution.

Summary

// TODO: insert the o2js.com blog post reference here.

This module tries to create secure random numbers with varying cryptographical strengths.

It tries to generate a random number, and it it fails tries two more times with a certain timeout. If it still fails the algorithm downgrades to a less secure random number generator and retries several times too.

If all entropy-based cryptographical methods fail, the generator fallbacks to a Math.random()-based algorithm; which is guaranteed to give a random number with indeterminate strength.

The cryptographical strengths of the generators are in the following order:

generateSecureRandom > generatePseudoRandom > generateRandom

Installation

$ npm install o2.random

Usage Example

// TODO: add server-side and client-side examples. // TODO: all readmes should have a similar structure.

var random = require('o2.random'),
    num1 , num2, num3;

//
// Cryptographically secure; pretty fast.
//
num1 = random.generateSecureRandom(12, function(err, data) {
    console.log('num1: "' + data + '"');
});

//
// Reasonably secure; pretty fast.
//
num2 = random.generatePseudoRandom(22, function(err, data) {
    console.log('num2: "' + data  + '"');
});

//
// The Fastest of all;
// The least secure of all;
//
// Still has enough entropy for large data;
// So it's practically suitable for most projects.
//
num3 = random.generateRandom(44, function(err, data) {
    console.log('num3: "' + data + '"');
});

Generates an output similar to this:

/usr/local/bin/node index.js
num3: "decb79ab102201a25ca38235f3d34cab9d32a81fc04198cc4dd40cafac08788affd9ec40ca8abe2f849b7f3a"
num1: "cd645968f31d22dcc6764f9f"
num2: "7c4b8e28bac17ca2f02a83bf682b1900348aa51bb61f"

Documentation

// TODO: add live url

See DOCUMENTATION.md

Contact Information