-
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.
Renamed `nextFloat` to `nextFloat64`. See #1.
- Loading branch information
1 parent
b1499a6
commit 8f6f776
Showing
12 changed files
with
107 additions
and
14 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,7 @@ | ||
const _fill = (next, prng, array, i = 0, j = array.length) => { | ||
for (; i < j; ++i) { | ||
array[i] = next(prng); | ||
} | ||
}; | ||
|
||
export default _fill; |
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,65 @@ | ||
import _fill from './_fill'; | ||
import nextUint8 from './nextUint8'; | ||
import nextUint16 from './nextUint16'; | ||
import nextInt32 from './nextInt32'; | ||
import nextFloat32 from './nextFloat32'; | ||
import nextFloat64 from './nextFloat64'; | ||
import nextBigInt64 from './nextBigInt64'; | ||
import nextBigUint64 from './nextBigUint64'; | ||
|
||
const fill = (prng, array, i, j) => { | ||
switch (array.constructor) { | ||
case ArrayBuffer: | ||
return _fill(nextUint8, new Uint8Array(array), i, j); | ||
|
||
case Int8Array: | ||
case Uint8Array: | ||
case Uint8ClampedArray: | ||
return _fill( | ||
nextUint8, | ||
prng, | ||
new Uint8Array(array.buffer, array.byteOffset, array.byteLength), | ||
i, | ||
j, | ||
); | ||
|
||
case Int16Array: | ||
case Uint16Array: | ||
return _fill( | ||
nextUint16, | ||
prng, | ||
new Uint16Array(array.buffer, array.byteOffset, array.length), | ||
i, | ||
j, | ||
); | ||
|
||
case Int32Array: | ||
case Uint32Array: | ||
return _fill( | ||
nextInt32, | ||
prng, | ||
new Int32Array(array.buffer, array.byteOffset, array.length), | ||
i, | ||
j, | ||
); | ||
|
||
case Float32Array: | ||
return _fill(nextFloat32, prng, array, i, j); | ||
|
||
case Float64Array: | ||
return _fill(nextFloat64, prng, array, i, j); | ||
|
||
case BigInt64Array: | ||
return _fill(nextBigInt64, prng, array, i, j); | ||
|
||
case BigUint64Array: | ||
return _fill(nextBigUint64, prng, array, i, j); | ||
|
||
default: | ||
throw new Error( | ||
`fill(prng, array, ...): array with constructor '${array.constructor.name}' not implemented`, | ||
); | ||
} | ||
}; | ||
|
||
export default fill; |
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,16 +1,18 @@ | ||
import nextFloat from './nextFloat'; | ||
import fill from './fill'; | ||
import nextFloat64 from './nextFloat64'; | ||
import nextInt32 from './nextInt32'; | ||
import nextUint64 from './nextUint64'; | ||
import splitmix64 from './splitmix64'; | ||
import xoroshiro128plus from './xoroshiro128plus'; | ||
|
||
/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */ | ||
export default { | ||
nextFloat, | ||
fill, | ||
nextFloat64, | ||
nextInt32, | ||
nextUint64, | ||
splitmix64, | ||
xoroshiro128plus, | ||
}; | ||
|
||
export {nextFloat, nextInt32, nextUint64, splitmix64, xoroshiro128plus}; | ||
export {fill, nextFloat64, nextInt32, nextUint64, splitmix64, xoroshiro128plus}; |
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 @@ | ||
import nextBigUint64 from './nextBigUint64'; | ||
|
||
export default function nextBigInt64(prng) { | ||
return nextBigUint64(prng) - BigInt(2 ** 63); | ||
} |
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 nextBigUint64(prng) { | ||
const a = prng.next().value; | ||
const b = prng.next().value; | ||
return BigInt(a) * BigInt(2 ** 32) + BigInt(b); | ||
} |
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,4 @@ | ||
export default function nextFloat32(prng) { | ||
const x = prng.next().value; | ||
return (x >>> 9) / 2 ** 23; | ||
} |
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,3 @@ | ||
export default function nextUint16(prng) { | ||
return (prng.next().value >>> 16) & 0xffff; | ||
} |
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 nextUint8(prng) { | ||
return (prng.next().value >>> 24) & 0xff; | ||
} |
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