10000){die("Error:
The list is limited to 10.000 items.");}
// Elements in the array are mixed randonly, so a randon order of elements is generated
shuffle ($array);
// Number of items to be selected is included in array $NoSelected
$NoSelected=$_POST["NoSelected"];
if($NoSelected=="0"){$NoSelected=sizeof($array);}
// $NoSelected items form $array are selected and saved in variable $selectedItems
$selectedItems="";
$temp="";
foreach ($array as $key => $val){
if($key<$NoSelected){$selectedItems.=trim($val)."\n";}
$temp.=trim($val)."\n";
}
}
// OPTION 2
// for random selection of numbers within a range
if($_POST["NoN"]!=""){
$NoN=trim($_POST["NoN"]);
if (str_is_int($NoN)!=1){die("Error:
$NoN is not a number.");}
if($NoN>10000){die("Error:
Results are limited to 10.000 randon numbers.");}
$Nofrom=trim($_POST["Nofrom"]);
if (str_is_int($Nofrom)!=1){die("Error:
$Nofrom is not a number.");}
$Noto=trim($_POST["Noto"]);
if (str_is_int($Noto)!=1){die("Error:
$Noto is not a number.");}
if ($Nofrom>=$Noto){die("Error:
The range is not correct");}
$decimals=$_POST["decimals"]*1;
$selectedItems="";
if ($decimals>0){
for($i=0;$i<$NoN;$i++){
$rand=mt_rand($Nofrom*10*$decimals,$Noto*pow(10,$decimals));
$rand=$rand/pow(10,$decimals);
$selectedItems.=$rand."\n";
}
}else{
for($i=0;$i<$NoN;$i++){
$rand=mt_rand($Nofrom,$Noto);
$selectedItems.=$rand."\n";
}
}
}
// OPTION 3
// for random selection of numbers with normal distribution
if($_POST["NoM"]!=""){
// here the input data is checked
$NoM=trim($_POST["NoM"]);
if (str_is_int($NoM)!=1){die("Error:
$NoM is not a number.");}
if($NoM>1000){die("Error:
Results are limited to 1.000 numbers.");}
$NoMedian=trim($_POST["NoMedian"]);
if (str_is_int($NoMedian)!=1){die("Error:
Median ($NoMedian) is not a number.");}
$NoStd=trim($_POST["NoStd"]);
if (str_is_int($NoStd)!=1){die("Error:
Standard Deviation ($NoStd) is not a number.");}
$decimals2=$_POST["decimals2"]*1;
// next function will obtained the set of random numbers
// see function at the end of the file
$NormalDistributedNumbers=get_normal_distributed_values($NoM,$NoMedian,$NoStd,$decimals2);
// numbers are saved to variable $selectedItems
$selectedItems="";
foreach($NormalDistributedNumbers as $k => $v){
$selectedItems.=$v."\n";
}
}
// OPTION 4
// for random selection of strings
if($_POST["NoS"]!=""){
$NoS=trim($_POST["NoS"]);
if (str_is_int($NoS)!=1){die("Error:
$NoS is not a number.");}
if($NoN>1000){die("Error:
Results are limited to 1.000 randon string.");}
$Nolen=trim($_POST["Nolen"]);
if (str_is_int($Nolen)!=1){die("Error:
$Nolen is not a number.");}
if($Nolen>200){die("Error:
Randon strings are limited to 200 characters.");}
$types["0"]="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYZ";
$types["1"]="1234567890";
$types["2"]="abcdefghijklmnopqrstuvwxyz";
$types["3"]="ABCDEFGHIJKLMNOPQRSTUVWYZ";
$types["4"]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYZ";
$types["5"]="1234567890abcdefghijklmnopqrstuvwxyz";
$types["6"]="1234567890ABCDEFGHIJKLMNOPQRSTUVWYZ";
$Notype=$_POST["NoType"];
$str = $types[$Notype];
$selectedItems="";
for($i=0;$i<$NoS;$i++){
$rand=generatepassword_from_string($str,$Nolen); // see function at the end of the file
$selectedItems.=$rand."\n";
}
}
// OPTION 5
// for random selection of strings with input format
if($_POST["NoX"]!=""){
$NoX=trim($_POST["NoX"])*1;
if (str_is_int($NoX)!=1){die("Error:
$NoX is not a number.");}
if($NoX>1000){die("Error:
Results are limited to 1.000 randon string.");}
$code=trim($_POST["Noformat"]);
$code=preg_replace("/[^CcVvXxNn]/","",$code);
if(strlen($code)>200){die("Error:
Length of string format is limited to 200 randon string.");}
$selectedItems="";
for($i=0;$i<$NoX;$i++){
$rand=generatepassword_from_code($code); // see function at the end of the file
$selectedItems.=$rand."\n";
}
}
// ################################################################################
// ################################## OUTPUT #################################
// ################################################################################
?>
\n";
print "Randonly selected items: \n"; if($_POST["NoM"]!=""){print_results($NormalDistributedNumbers,$NoMedian,$NoStd);} // prints a table with statistics for option 3 print " |
Powered by PHPTutorial.info
Get the code here
\n";
print " Statistics on distribution of the data above.
|
NOTE: providing random data with perfect normal distribution is very hard.
";
print "This service generated 100 sets of data and them the data closer to desired standard deviation was selected.";
print "\n";
}
function sum ($nums) {
$temp = 0;
foreach ($nums as $key => $val) {
$temp += $val;
}
return $temp;
}
function sum2 ($nums) {
$temp = 0;
foreach ($nums as $key => $val) {
$temp += pow($val,2);
}
return $temp;
}
function mean ($nums) {
$temp = 0;
foreach ($nums as $key => $val) {
$temp += $val;
}
return $temp/sizeof($nums);;
}
function median ($nums) {
$n = count($nums);
sort($nums);
if ($n & 1) {
return $nums [($n-1)/2];
} else {
return ($nums [($n-1)/2] + $nums [$n/2])/2;
}
}
function mode ($nums) {
foreach ($nums as $key => $val) {
$counts[$val]++;
}
arsort($counts);
if (count($nums)==count($counts)){
return "frequency for each data is 1";
}else{
return key($counts);
}
}
function variance ($nums) {
$n = count($nums);
$mean = mean($nums);
foreach ($nums as $key => $val) {
$temp += pow($val - $mean, 2);
}
return $temp/$n;
}
function sd ($nums) {
return sqrt(variance($nums));
}
function skewness ($nums) {
$n = count($nums);
$mean = mean($nums);
$sd = sd($nums);
foreach ($nums as $key => $val) {
$temp += pow(($val - $mean), 3);
}
$s = $temp/(($n - 1)*pow($sd,3));
return $s;
}
function kurtosis ($nums) {
$n = count($nums);
$mean = mean($nums);
$sd = sd($nums);
foreach ($nums as $key => $val) {
$temp += pow(($val - $mean), 4);
}
$s = ($temp/(($n - 1)*pow($sd,4)))-3;
return $s;
}
?>