-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom.js
More file actions
39 lines (33 loc) · 958 Bytes
/
custom.js
File metadata and controls
39 lines (33 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const pd = require('probability-distributions');
function customFaker (numOfSamples) {
let len = Math.abs(numOfSamples);
let endIndex = len - 1;
let currentIndex = -1;
function PrecomputedSamples(numOfSamples) {
this.numOfSamples = numOfSamples;
this.samples = {};
PrecomputedSamples.prototype.init = () => {
this.samples.height = pd.rnorm(this.numOfSamples, 172, 4.5 );
this.samples.weight = pd.rnorm(this.numOfSamples, 72, 7 );
}
this.init();
}
let precomputedSamples = new PrecomputedSamples(len);
let samples = {
get next() {
if (currentIndex == endIndex) {
currentIndex = -1;
}
++currentIndex;
return this;
},
height(options) {
return precomputedSamples.samples.height[currentIndex];
},
weight(options) {
return precomputedSamples.samples.weight[currentIndex];
}
}
return () => samples;
}
module.exports = customFaker;