-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRandomData.php
More file actions
45 lines (33 loc) · 1.01 KB
/
RandomData.php
File metadata and controls
45 lines (33 loc) · 1.01 KB
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
43
44
45
<?php
$cd = dirname(__FILE__);
$id = $group = $num1 = $num2 = $bool = $date = [];
$letters = 'ABCDEFGHIJKLMNOPQRSTUVXWYZ';
srand(99);
// Credit - @Paulpro: https://stackoverflow.com/a/15952104/1422451
function nrand($mean, $sd){
$x = mt_rand()/mt_getrandmax();
$y = mt_rand()/mt_getrandmax();
return sqrt(-2*log($x))*cos(2*pi()*$y)*$sd + $mean;
}
for ($i=0; $i<20; $i++){
$id[] = rand(1,15);
$group[] = substr($letters, rand(0,25), 1);
$num1[] = nrand(0,1)*100;
$num2[] = nrand(0,1);
$bool[] = [True, False][rand(0,1)];
$date[] = date("Y-m-d H:i:s", rand(0,time()));
}
var_dump($bool);
for ($f=1; $f<=10; $f++){
$strfile = $cd.'/RandomData_PHP_'. $f .'.csv';
echo $strfile."\n";
$fs = fopen($strfile, 'w');
fputcsv($fs, ["ID", "GROUP", "NUM1", "NUM2", "BOOL", "DATE"]);
fclose($fs);
for ($i=0; $i<20; $i++){
$fs = fopen($strfile, 'a');
fputcsv($fs, array($id[$i], $group[$i], $num1[$i], $num2[$i], $bool[$i], $date[$i]));
fclose($fs);
}
}
?>