JSPM

crypto-random-int

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 29
  • Score
    100M100P100Q58442F
  • License ISC

get a cryptographically random integer within a range

Package Exports

  • crypto-random-int

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (crypto-random-int) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Crypto-Random-Int

This module produces a function that returns a promise to find a cryptographically safe random integer within in the range and including the two integer arguments. The difference between the two integers must be less than 232. It works in Node JS or a browser.

Install

npm install crypto-random-int 

Usage in Node

const cryptoRandomInt = require("crypto-random-int");

cryptoRandomInt(-7, 28)
    .then((randomInt) => { 
        console.log(randomInt); 
    })
    .catch((err) => {
        console.log(err); 
    });

Usage in browser

Download the repository and reference the crypto-random-int.js file as shown below. cryptoRandomInt is placed on the window object and can be referenced globally.

<script src="path/to/crypto-random-int.js"></script>
<script>

let promises = Array(7).fill().map(x => cryptoRandomInt(9, 0));

Promise.all(promises)
    .then((arr) => {
        console.log(arr);
    })
    .catch((err) => {
        console.log(err);
    });

</script>