src/generators/random.js   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 21
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 9
mnd 0
bc 0
fnc 2
dl 0
loc 21
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A RandomGenerator.generate 0 11 2
1
/* eslint-disable no-magic-numbers */
2
import crypto from 'crypto';
3
import Generator from './Base';
4
5
/**
6
 * Generates a random number from 0 to 1.
7
 * @returns {number} number
8
 * @generator
9
 */
10
export default class RandomGenerator extends Generator {
11
    generate() {
12
        const bytes = crypto.randomBytes(7);
13
14
        let randomValue = (bytes[0] % (2 ** 5)) / (2 ** 5);
15
16
        bytes.slice(1).forEach(byte => {
17
            randomValue = (randomValue + byte) / (2 ** 8);
18
        });
19
20
        return randomValue;
21
    }
22
}
23