This repository has been archived by the owner on Apr 2, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(random): adds several ways of generating seeded random numbers
Using the pure-rand library, we now provide several ways to generate seeded random data: xorshift128plus, mersenne, xoroshiro128plus, congruential, congruential32
- Loading branch information
Showing
10 changed files
with
310 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
# Random Number Generating Methods | ||
|
||
These methods create reproducible sequences of random numbers given an initial seed value. | ||
|
||
This methods rely on the [pure-rand](https://github.com/dubzzz/pure-rand) project. | ||
|
||
## random | ||
|
||
Generates random numbers using the Mersenne Twister generator whose values are within the range 0 to 0xffffffff. | ||
|
||
{% tabs %} | ||
{% tab title="Usage" %} | ||
|
||
```typescript | ||
const SEED = 5; | ||
const sequence: Seq<number> = random(SEED); | ||
``` | ||
|
||
{% endtab %} | ||
|
||
{% tab title="Type Definition" %} | ||
|
||
```typescript | ||
type random = (seed = DEFAULT_SEED) => Seq<number>; | ||
``` | ||
|
||
{% endtab %} | ||
{% endtabs %} | ||
|
||
## mersenne | ||
|
||
Generates random numbers using the Mersenne Twister generator whose values are within the range 0 to 0xffffffff. | ||
|
||
{% tabs %} | ||
{% tab title="Usage" %} | ||
|
||
```typescript | ||
const SEED = 5; | ||
const sequence: Seq<number> = mersenne(SEED); | ||
``` | ||
|
||
{% endtab %} | ||
|
||
{% tab title="Type Definition" %} | ||
|
||
```typescript | ||
type mersenne = (seed = DEFAULT_SEED) => Seq<number>; | ||
``` | ||
|
||
{% endtab %} | ||
{% endtabs %} | ||
|
||
## xorshift128plus | ||
|
||
Generates random numbers using the xorshift128+ generator whose values are within the range -0x80000000 to 0x7fffffff. | ||
|
||
{% tabs %} | ||
{% tab title="Usage" %} | ||
|
||
```typescript | ||
const SEED = 5; | ||
const sequence: Seq<number> = xorshift128plus(SEED); | ||
``` | ||
|
||
{% endtab %} | ||
|
||
{% tab title="Type Definition" %} | ||
|
||
```typescript | ||
type xorshift128plus = (seed = DEFAULT_SEED) => Seq<number>; | ||
``` | ||
|
||
{% endtab %} | ||
{% endtabs %} | ||
|
||
## xoroshiro128plus | ||
|
||
Generates random numbers using the xoroshiro128+ generator whose values are within the range -0x80000000 to 0x7fffffff. | ||
|
||
{% tabs %} | ||
{% tab title="Usage" %} | ||
|
||
```typescript | ||
const SEED = 5; | ||
const sequence: Seq<number> = xoroshiro128plus(SEED); | ||
``` | ||
|
||
{% endtab %} | ||
|
||
{% tab title="Type Definition" %} | ||
|
||
```typescript | ||
type xoroshiro128plus = (seed = DEFAULT_SEED) => Seq<number>; | ||
``` | ||
|
||
{% endtab %} | ||
{% endtabs %} | ||
|
||
## congruential | ||
|
||
Generates random numbers using a Linear Congruential generator whose values are within the range 0 to 0x7fff. | ||
|
||
{% tabs %} | ||
{% tab title="Usage" %} | ||
|
||
```typescript | ||
const SEED = 5; | ||
const sequence: Seq<number> = congruential(SEED); | ||
``` | ||
|
||
{% endtab %} | ||
|
||
{% tab title="Type Definition" %} | ||
|
||
```typescript | ||
type congruential = (seed = DEFAULT_SEED) => Seq<number>; | ||
``` | ||
|
||
{% endtab %} | ||
{% endtabs %} | ||
|
||
## congruential32 | ||
|
||
Generates random numbers using a Linear Congruential generator whose values are within the range 0 to 0xffffffff. | ||
|
||
{% tabs %} | ||
{% tab title="Usage" %} | ||
|
||
```typescript | ||
const SEED = 5; | ||
const sequence: Seq<number> = congruential32(SEED); | ||
``` | ||
|
||
{% endtab %} | ||
|
||
{% tab title="Type Definition" %} | ||
|
||
```typescript | ||
type congruential32 = (seed = DEFAULT_SEED) => Seq<number>; | ||
``` | ||
|
||
{% endtab %} | ||
{% endtabs %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.