-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumberGenerator.php
42 lines (38 loc) · 1.43 KB
/
NumberGenerator.php
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
42
<?php
// ============================================================================
class NumberGenerator extends FlexDataGen {
/*
Generates a random number in the given [min,max] range using the given
distribution and desired number of decimal digits.
*/
// ============================================================================
protected $distribution;
// ------------------------------------------------------------------------
public function __construct(
$options = [/*
min: number (required)
max: number (required)
decimals: int (optional) = 0
distribution: class name (required)
*/]
) {
// ------------------------------------------------------------------------
parent::__construct($options);
if(!isset($options['decimals'])) {
$this->options['decimals'] = 0;
}
$this->distribution = Helper::getInstanceArgs(
$this->options['distribution'], [
$this->options['min'],
$this->options['max'],
$this->options
]);
}
// ------------------------------------------------------------------------
protected function generateValue(
$row_no
) {
// ------------------------------------------------------------------------
return $this->distribution->getRandomValue($this->options['decimals']);
}
}