-2
$C = $_POST['Cc'];
$X = $_POST['X'];
$CX = $_POST['Cc'] . $_POST['X'];

$NC = preg_replace_callback("/x/" ,function() {return rand(0,9);}, $CX);

            $New = $NC ;
            $NNew =  str_repeat($New,10);
            echo $NNew;

what's wrong when i output it , it gives me the same number How to make It Don't Give me the same Numbers ??

1 Answers1

1

It's basically you are not changing the seed for the rand method. Each time it's getting same seed and generating same number.

Read this PHP manual : http://php.net/manual/en/function.srand.php

Check the code snippet below:

<?php

// seed with microseconds
function make_seed()
{
  list($usec, $sec) = explode(' ', microtime());
  return $sec + $usec * 1000000;
}
srand(make_seed());
$randval = rand(0,9);

echo $randval;


?>

Or you can use mt_rand() which is seeded differently on each execution.

Ahmad Faiyaz
  • 316
  • 4
  • 16