random.org-javascript

1.0.4 • Public • Published

random.org.js NPM Version Build Status Dependencies Vuln

Table of Contents

Installation

Install with npm

$ npm install random.org-javascript

Usage

ES6

import random from "random.org-javascript";

CommonJS

const random = require("random.org-javascript");

Basic Example

You can use Promise

random.generateInteger(1, 50, 10, "Decimal").then(response => {
    console.log(response); // => Array<number>[10]
}).catch(error => {
    console.log(error);
});

or async

try {
    let response = await random.generateInteger(10, 50, 10, "Decimal")
    console.log(response); // => Array<number>[10]
} catch (error) {
    console.log(error);
}

Examples

Generating Random Number

random.generateInteger(1, 50, 10, "Decimal").then(response => {
    console.log(response); // => Array<number>[10]
}).catch(error => {
    console.log(error);
});

Generating Random Number Sequence

random.generateIntegerSequences(1, 50).then(response => {
    console.log(response); // => Array<number>[50]
}).catch(error => {
    console.log(error);
});

Generating Random String

random.generateStrings(10, 5).then(response => {
    console.log(response); // => Array<string[5]>[10]
}).catch(error => {
    console.log(error);
});

Getting Quota

random.getQuota().then(response => {
    console.log(response); // => 1000000 (If you have not generated anything yet)
}).catch(error => {
    console.log(error);
});

API

generateInteger(min, max, amount, format)

Generates true random integers within a user-defined range

  • Parameters:
    • minnumber — The smallest value allowed for each integer.
    • maxnumber — The largest value allowed for each integer.
    • amountnumber[optional] — The number of integers requested.
    • formatstring[optional] — The format that will be used to print the numbers, i.e., binary, octal, decimal or hexadecimal.
  • Returns: Promise<Array<number>> — Promise Array of number.

generateIntegerSequences(min, max)

Generates uniform or multiform sequences of true random integers within user-defined ranges.

  • Parameters:
    • minnumber — The lower bound of the interval (inclusive).
    • maxnumber — The upper bound of the interval (inclusive).
  • Returns: Promise<Array<number>> — Promise Array of number.

generateStrings(amount, length, enableNumber?, enableUppercase?, enableLowercase?, enableUnique?)

Generates true random strings.

  • Parameters:
    • amountnumber — The number of strings requested.
    • lengthnumber — The length of the strings. All the strings produced will have the same length.
    • enableNumbeeboolean[optional: true] — Determines whether digits (0-9) are allowed to occur in the strings.
    • enableUppercaseboolean[optional: true] — Determines whether uppercase alphabetic characters (A-Z) are allowed to occur in the strings.
    • enableLowercaseboolean[optional]: true — Determines lowercase alphabetic characters (a-z) are allowed to occur in the strings.
    • enableUniqueboolean[optional: true] — Determines whether the strings picked should be unique (as a series of raffle tickets drawn from a hat) or not (as a series of die rolls).
  • Returns: Promise<Array<string>> — Promise Array of String.

getQuota()

This allows you to examine your quota at any point in time. The quota system works on the basis of IP addresses. Each IP address has a base quota of 1,000,000 bits. When your client makes a request for random numbers (or strings, etc.), the server deducts the number of bits it took to satisfy your request from the quota associated with your client's IP address.

  • Returns: Promise<number> — Promise Number

Package Sidebar

Install

npm i random.org-javascript

Weekly Downloads

4

Version

1.0.4

License

BSD-3-Clause

Unpacked Size

15.3 kB

Total Files

8

Last publish

Collaborators

  • mradhit