Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

Commit 9318e43

Browse files
Load PRNGs from the seedrandom package instead of vendorizing
1 parent 4745500 commit 9318e43

File tree

3 files changed

+3
-109
lines changed

3 files changed

+3
-109
lines changed

packages/library/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"es6-promise": "^4.1.0",
2020
"file-saver": "^1.3.3",
2121
"lodash": "^4.14.1",
22+
"seedrandom": "^2.4.3",
2223
"whatwg-fetch": "^2.0.3"
2324
},
2425
"devDependencies": {

packages/library/src/util/random.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { clamp } from 'lodash'
2-
import { impl } from '../vendor/alea'
2+
import { alea } from 'seedrandom'
33

44
// Random uuid4 generation
55
export const uuid4 = (random=Math.random) =>
@@ -16,19 +16,8 @@ export const uuid4 = (random=Math.random) =>
1616
export class Random {
1717
constructor(options={}) {
1818
if (options.algorithm === 'alea') {
19-
// If no seed is given, autoseed the PRNG using
20-
// a (mostly) random 256-character string
21-
// (This seeding mechanism is loosely based on
22-
// the priming mechanism in the seedrandom package
23-
// by David Bau, https://github.com/davidbau/seedrandom)
24-
if (!options.seed) {
25-
// IE 11 uses a vendor prefix for the crypto module
26-
const randomValues = (window.mscrypto || window.crypto)
27-
.getRandomValues(new Uint8Array(256))
28-
options.seed = String.fromCharCode(...randomValues)
29-
}
3019
// Generate a PRNG using the alea algorithm
31-
this.random = impl(options.seed)
20+
this.random = alea(options.seed)
3221
} else {
3322
// Fallback to the built-in random generator
3423
this.random = Math.random

packages/library/src/vendor/alea.js

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)