mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
16 lines
475 B
JavaScript
16 lines
475 B
JavaScript
import RandomGenerator from './AbstractRandomGenerator';
|
|
|
|
// cryptographically strong PRNGs available in modern browsers
|
|
export default class BrowserRandomGenerator extends RandomGenerator {
|
|
/**
|
|
* @name Random.fraction
|
|
* @summary Return a number between 0 and 1, like `Math.random`.
|
|
* @locus Anywhere
|
|
*/
|
|
fraction () {
|
|
const array = new Uint32Array(1);
|
|
window.crypto.getRandomValues(array);
|
|
return array[0] * 2.3283064365386963e-10; // 2^-32
|
|
}
|
|
}
|