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 ################################# // ################################################################################ ?> Random Chooser

Random Chooser

A tool for random selection of items and generation of random numbers, strings and passwords
Randon select text";}else{print "Randon select text";} ?> | Random numbers 1";}else{print "Random numbers 1";} ?> | Random numbers 2";}else{print "Random numbers 2";} ?> | Random strings 1";}else{print "Random strings 1";} ?> | Random strings 2";}else{print "Random strings 2";} ?>  

Enter choices in the text area below (one per line). | Example

Pick randomly elements from the list

Select > numbers with decimals within the range > to >

 

Select > numbers with decimals with Normal Distribution:

Median> | Standard Deviation>

 

Select > strings which are> characters long
and use those characters:

 

Select > strings whith > format*.

The purpose of this tool is to generate readable passwords

*Examples of formats and random strings
CVcvcvNN: TAsuvo80, QUyita45, HAhagi85, YEjuho20, NIjoka73...

C: upper case consonant; c: lower case consonant; V: upper case vowel; v: lower case vowel; N/n: number; X/x: vowel, consonant or number
Other characters with be removed from the format.

 

\n"; print "
\n"; print "Randonly selected items:
\n"; print "\n"; print "
\n"; if($_POST["NoM"]!=""){print_results($NormalDistributedNumbers,$NoMedian,$NoStd);} // prints a table with statistics for option 3 print "
\n"; } ?>


Powered by PHPTutorial.info

Get the code here

$type){ // any letter or digits if($type=="X" or $type=="x"){ $password.= substr($all,mt_rand(0,61),1); } // consonant, upper case if($type=="C"){ $password.= substr($consonants,mt_rand(0,20),1); } // consonant, lower case if($type=="c"){ $password.= strtolower(substr($consonants,mt_rand(0,20),1)); } // vowel, upper case if($type=="V"){ $password.= substr($vowels,mt_rand(0,4),1); } // vowel, lower case if($type=="v"){ $password.= strtolower(substr($vowels,mt_rand(0,4),1)); } // vowel, lower case if($type=="N" or $type=="n"){ $password.= mt_rand(0,9); } } return $password; } // ################################################################################ // ALL FUNCTIONS BELLOW ARE USED BY OPTION 3 // FUNCTION TO GET NUMBERS WITH NORMAL DISTRIBUTION // Of course, the results will not much 100% the requested distribution function get_normal_distributed_values ($samples,$median,$std,$decimals){ // the function optains 100 sets of numbers and from them // the set with a standard deviation closser to the requested is selected // the selected set of numbers have a N(0,1) distribution $tozero=10000; $best=array(); for($try=0;$try<100;$try++){ $nums=array(); $i=0; // loop bellow generates a set of numbers with N(0,1) distribution (arry $nums) while($i<$samples){ // random number with N(0,1) distribution are generated in next line. $a=$u=sqrt(-2*log(mt_rand(0,99999999)/100000000))*cos(2*pi()*(mt_rand(0,99999999)/100000000)); if(abs($a)>2.5){continue;} $nums[$i]=$a; $i++; } $sd=sd($nums); $sd=abs(1-abs($sd)); // in next line it is checked whether the last set of numbers ($nums) has a // standard deviation closer to 1 than the previously selected one ($best). // If the new set is numbers better, it will be saved in array $best if($sd<$tozero){$tozero=$sd;$best=$nums;} } // array $best with N(0,1) distribution is modified to mach // the desired median, standard deviation and decimals foreach($best as $k => $v){ $best[$k]=round($v*$std+$median,$decimals); } return $best; } // FUNCTION TO COMPUTE AND SHOW SOME STATISTICS FOR DATA OPTAINED IN OPTION 3 // the basic code used bellow was optained // from http://biophp.org/stats/describe_data/ function print_results($array,$median,$std){ $data=""; foreach($array as $k => $v){ $data.=$v."\n"; } print "
\n"; print "
\n

Statistics on distribution of the data above.
The third column indicates the theoretical values of data with the requested distribution."; ?>
Parameter Value Ideal for Selected
Normal Distribution
No Samples: 
Mean:
Median:
Mode:
Variance:
Standard Deviation:
Skewness:0
Kurtosis:0
Minimum: 
Maximum: 
Range: 

\n\n"; print "

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; } ?>