https://github.com/kripod/hmac-rng.js
HMAC-based random number generator written in JavaScript.
https://github.com/kripod/hmac-rng.js
Last synced: about 1 year ago
JSON representation
HMAC-based random number generator written in JavaScript.
- Host: GitHub
- URL: https://github.com/kripod/hmac-rng.js
- Owner: kripod
- License: mit
- Created: 2016-01-04T20:00:04.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-03-06T16:52:59.000Z (over 10 years ago)
- Last Synced: 2025-03-21T11:43:17.820Z (about 1 year ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hmac-rng
[](https://npmjs.com/package/hmac-rng)
[](https://travis-ci.org/kripod/hmac-rng.js)
[](https://codeclimate.com/github/kripod/hmac-rng.js/coverage)
[](https://codeclimate.com/github/kripod/hmac-rng.js)
HMAC-based random number generator written in JavaScript.
## API Reference
* [HmacRng](#module_HmacRng)
* [HmacRng](#exp_module_HmacRng--HmacRng) ⏏
* [new HmacRng(seed, [algorithm])](#new_module_HmacRng--HmacRng_new)
* _instance_
* [.nextInt(min, max)](#module_HmacRng--HmacRng+nextInt) ⇒ number
* [.nextInts(min, max, amount)](#module_HmacRng--HmacRng+nextInts) ⇒ Array.<number>
* _static_
* [.defaultAlgorithm](#module_HmacRng--HmacRng.defaultAlgorithm)
* [.getRandomInt(seed, min, max)](#module_HmacRng--HmacRng.getRandomInt) ⇒ number
* [.getRandomInts(seed, min, max, amount)](#module_HmacRng--HmacRng.getRandomInts) ⇒ Array.<number>
* [.shuffleArray(seed, array)](#module_HmacRng--HmacRng.shuffleArray) ⇒ Array.<Object>
### HmacRng ⏏
**Kind**: Exported class
#### new HmacRng(seed, [algorithm])
Creates a new HMAC-RNG instance.
| Param | Type | Description |
| --- | --- | --- |
| seed | string | Seed used for randomization. |
| [algorithm] | string | Cryptographic algorithm to use HMAC with. |
#### hmacRng.nextInt(min, max) ⇒ number
Gets the next random integer in the current sequence.
The maximum range of 'min' and 'max' is 2^28 (268435456).
**Kind**: instance method of [HmacRng](#exp_module_HmacRng--HmacRng)
**Returns**: number - The generated random integer.
| Param | Type | Description |
| --- | --- | --- |
| min | number | Inclusive lower bound of the random integer returned. |
| max | number | Inclusive upper bound of the random integer returned. This must be greater than 'min'. |
#### hmacRng.nextInts(min, max, amount) ⇒ Array.<number>
Gets the next random integers in the current sequence.
The maximum range of 'min' and 'max' is 2^28 (268435456).
**Kind**: instance method of [HmacRng](#exp_module_HmacRng--HmacRng)
**Returns**: Array.<number> - The generated array of random integers.
| Param | Type | Description |
| --- | --- | --- |
| min | number | Inclusive lower bound of the random integers returned. |
| max | number | Inclusive upper bound of the random integers returned. This must be greater than 'min'. |
| amount | number | Amount of integers to be generated. |
#### HmacRng.defaultAlgorithm
Determines the default cryptographic algorithm to use HMAC with.
Useful for altering the output of static methods.
**Kind**: static property of [HmacRng](#exp_module_HmacRng--HmacRng)
#### HmacRng.getRandomInt(seed, min, max) ⇒ number
Generates a random integer using the default algorithm.
The maximum range of 'min' and 'max' is 2^28 (268435456).
**Kind**: static method of [HmacRng](#exp_module_HmacRng--HmacRng)
**Returns**: number - The generated random integer.
**Since**: 1.1.0
| Param | Type | Description |
| --- | --- | --- |
| seed | string | Seed used for randomization. |
| min | number | Inclusive lower bound of the random integer returned. |
| max | number | Inclusive upper bound of the random integer returned. This must be greater than 'min'. |
#### HmacRng.getRandomInts(seed, min, max, amount) ⇒ Array.<number>
Generates random integers using the default algorithm.
The maximum range of 'min' and 'max' is 2^28 (268435456).
**Kind**: static method of [HmacRng](#exp_module_HmacRng--HmacRng)
**Returns**: Array.<number> - The generated array of random integers.
**Since**: 1.1.0
| Param | Type | Description |
| --- | --- | --- |
| seed | string | Seed used for randomization. |
| min | number | Inclusive lower bound of the random integers returned. |
| max | number | Inclusive upper bound of the random integers returned. This must be greater than 'min'. |
| amount | number | Amount of integers to be generated. |
#### HmacRng.shuffleArray(seed, array) ⇒ Array.<Object>
Shuffles the given array using the default algorithm.
**Kind**: static method of [HmacRng](#exp_module_HmacRng--HmacRng)
**Returns**: Array.<Object> - The array which has been shuffled.
**Since**: 1.1.0
| Param | Type | Description |
| --- | --- | --- |
| seed | string | Seed used for randomization. |
| array | Array.<Object> | Array to be shuffled. |