0.0.1 • Published 5 years ago
node-random-int v0.0.1
node-random-int
Cryptographically secure pseudo-random number generator for node.js
The core logic is loosely based on the node-random-number-csprng project by joepie91
Install
npm install node-random-int
#Usage ###Async:
import {createRandomNumberGenerator} from 'node-random-int';
async function FOO(){
const randomNumberGenerator = createRandomNumberGenerator(0, 100);
const randomInt1 = await randomNumberGeneraton.nextValueAsync();
const randomInt2 = await randomNumberGeneraton.nextValueAsync();
}
Can also be consumed via for await
loop:
import {createRandomNumberGenerator} from 'node-random-int';
async function FOO(){
const randomNumberGenerator = createRandomNumberGenerator(0, 100);
for await(let randomInt of randomNumberGenerator){
// this will loop indefinitely!
// you must implement some kind of break logic
if(randomInt > 2){
break;
}
}
}
convenience method:
import {getRandomIntegerAsync} from 'node-random-int';
async function FOO(){ // each invocation creates a new randomNumberGenerator object const randomInt1 = await getRandomIntegerAsync(0, 100); const randomInt2 = await getRandomIntegerAsync(0, 100); }
###Synchronous
```typescript
import {createRandomNumberGenerator} from 'node-random-int';
const randomNumberGenerator = createRandomNumberGenerator(0, 100);
const randomInt1 = randomNumberGeneraton.nextValueSync();
const randomInt2 = randomNumberGeneraton.nextValueSync();
Can be consumed synchronously via for
loop:
import {createRandomNumberGenerator} from 'node-random-int';
const randomNumberGenerator = createRandomNumberGenerator(0, 100);
for (let randomInt of randomNumberGenerator){
// this will loop indefinitely!
// you must implement some kind of break logic
if(randomInt > 2){
break;
}
}
convenience method:
import {getRandomInteger} from 'node-random-int';
function FOO(){ // each invocation creates a new randomNumberGenerator object const randomInt1 = getRandomInteger(0, 100); const randomInt2 = getRandomInteger(0, 100); }
##Tests
```typescript
npm run test
##Licence
0.0.1
5 years ago