I'm using a function to generate random values using TAG including parameters as Length, type of random : Alphabetic, Numeric or Mix, and LowerCase, Uppercase. Now this issue is that I want to store or save, fix or freeze, a random result to use it in multiples places. For exemple instead of RAND, I use FixRAND, then the result will be the same in the whole page as long as TAG have the same parameters.
To give you a small idea of what I already have. It's fully functional when I use some TAGs Like [RAND,10,A,U] but It generate random values every time. I need to add another TAG that can store some how the same results upon the same request.
function generateRandom($length,$type,$gen){
switch ($type) {
case 'A':
$rd= "";
srand((double)microtime()*1000000);
$data = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ";
for($i = 0; $i < $length; $i++){
$rd .= substr($data, (rand()%(strlen($data))), 1);
}
break;
case 'N':
$rd= "";
srand((double)microtime()*1000000);
$data = '0123456789';
for($i = 0; $i < $length; $i++){
$rd .= substr($data, (rand()%(strlen($data))), 1);
}
break;
case 'M':
$rd= "";
srand((double)microtime()*1000000);
$data = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789";
for($i = 0; $i < $length; $i++){
$rd .= substr($data, (rand()%(strlen($data))), 1);
}
break;
}
if ( $gen == 'U') $rd = strtoupper($rd);
if ( $gen == 'L') $rd = strtolower($rd);
return $rd;
}
$replaced_xxxxxx=str_replace("[MESSAGE]","$message",$replaced_xxxxxx);
preg_match_all("/\[RAND,[0-9]+,[AMN],[LU]\]/",$replaced_xxxxxx,$random_tag_array);
foreach ($random_tag_array[0] as $random_tag) {
$random_stripped=$random_tag;
$random_stripped=str_replace("[RAND,","",$random_stripped);
$random_stripped=str_replace("]","",$random_stripped);
$random_exploded=explode(',', $random_stripped);
$random_generated=generateRandom($random_exploded[0],$random_exploded[1],$random_exploded[2]);
$replaced_xxxxxx=preg_replace($random_tag, $random_generated, $replaced_xxxxxx,1);