-
Notifications
You must be signed in to change notification settings - Fork 0
/
exponential.js
41 lines (39 loc) · 1.04 KB
/
exponential.js
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
40
41
var Random_Precision = 10000;
var exponential_rand = function (){
this.data_size = 200000;
this.index = 0;
this.data = [];
}
exponential_rand.prototype.exponential_rand_generator = function(landa){
for(i = 0; i< this.data_size; i++){
var rand_value = Math.random();
rand_value = Math.floor(rand_value*Random_Precision)/Random_Precision;
var x = Math.log(1-rand_value)/(-landa);
this.data.push(x);
}
}
exponential_rand.prototype.d_rand_generator = function(landa){
for(i = 0; i< this.data_size; i++){
// var rand_value = Math.random();
// rand_value = Math.floor(rand_value*Random_Precision)/Random_Precision;
// var x = Math.log(1-rand_value)/(-landa);
this.data.push(landa);
}
}
exponential_rand.prototype.init_picker = function(){
this.index = 0;
}
exponential_rand.prototype.take_queue = function(){
var temp = this.data[this.index];
this.index++;
if(this.index<=this.data_size){
return temp;
}
else{
return null;
}
}
exponential_rand.prototype.put_array = function(a){
this.data = a;
}
module.exports = exponential_rand;