-
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.
💥 BREAKING CHANGE: Move to more functional API.
- Loading branch information
1 parent
6e74f3f
commit 18bd143
Showing
8 changed files
with
57 additions
and
37 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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import SplitMix64 from './SplitMix64'; | ||
import nextFloat from './nextFloat'; | ||
import nextUint64 from './nextUint64'; | ||
import splitmix64 from './splitmix64'; | ||
|
||
/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */ | ||
export default { | ||
SplitMix64, | ||
nextFloat, | ||
nextUint64, | ||
splitmix64, | ||
}; | ||
|
||
export {SplitMix64}; | ||
export {nextFloat, nextUint64, splitmix64}; |
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,5 @@ | ||
export default function nextFloat(prng) { | ||
const a = prng.next().value; | ||
const b = prng.next().value; | ||
return (a >>> 0) / 2 ** 32 + (b >>> 0) / 2 ** 64; | ||
} |
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,3 @@ | ||
export default function nextUint64(prng) { | ||
return [prng.next().value, prng.next().value]; | ||
} |
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,12 @@ | ||
import {add64, mul64, xor64, shr64, get64} from '@aureooms/js-uint64'; | ||
|
||
export default function* splitmix64(seed) { | ||
let state = get64(...seed); | ||
while (true) { | ||
state = add64(state, get64(0x9e3779b9, 0x7f4a7c15)); | ||
let z = state; | ||
z = mul64(xor64(z, shr64(z, 30)), get64(0xbf58476d, 0x1ce4e5b9)); | ||
z = mul64(xor64(z, shr64(z, 27)), get64(0x94d049bb, 0x133111eb)); | ||
yield* xor64(z, shr64(z, 31)); | ||
} | ||
} |
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