README
# XRTLibrary-PRNG
Introduction
A C#-compatible PRNG (pseudo random number generator).
Reference(s)
Disclaimer:
- To be compatible with C# implementation (typically .NET Core 2.1) is the only warranty that this module provides.
- If you thought that the algorithm is vulnerable, send your complain to Microsoft, not us.
Installation
To install this package, you can use NPM by typing following command:
npm install xrtlibrary-prng --save
Then you can import this library in your JavaScript code:
const XRTLibPRNG = require("xrtlibrary-prng");
API
(Class) RandomGenerator
Random generator.
new RandomGenerator([seed])
Construct a new object.
Exception(s):
- RandomGenerator.OverflowError: Raised if the seed value is not a 32-bit signed integer.
Parameter(s):
- seed (Number): (Optional) The random seed (a 32-bit signed integer, a random number will be used as the seed if this parameter is not set).
prng.next()
Get a random integer.
Return value:
- (Number) An integer [0...INT32_MAX).
prng.nextInRange(minValue, maxValue)
Get a random integer (within specific range).
Exception(s):
- RandomGenerator.OutOfRangeError: Raised if the range is invalid (the minimum value is larger than the maximum value).
Parameter(s):
- minValue (Number): The minimum value.
- maxValue (Number): The maximum value.
Return value:
- (Number) An integer [minValue, maxValue).
prng.nextInRangeMaxOnly(maxValue)
Get a random integer (within [0..maxValue)).
Exception(s):
- RandomGenerator.OutOfRangeError: Raised if the maximum value is invalid (lower than 0).
Parameter(s):
- maxValue (Number): The maximum value.
Return value:
- (Number) An integer [0..maxValue).
prng.nextDouble()
Get a random double.
Return value:
- (Number) A random double.
prng.nextBytes(length)
Get a series of random bytes.
Parameter(s):
- length (Number): The length.
Return value:
- (Buffer) The bytes.
prng.nextBytesInPlace(buffer)
Get a series of random bytes (in place).
Parameter(s):
- buffer (Buffer): The buffer.
(Class) RandomGenerator.Error
Random generator error.
Extend(s):
- Error
(Class) RandomGenerator.OutOfRangeError
Random generator out of range error.
Extend(s):
- RandomGenerator.Error
(Class) RandomGenerator.OverflowError
Random generator overflow error.
Extend(s):
- RandomGenerator.Error