I am trying to genarate random number of any length i want to make product id and order id. But the problem here is when i create new item giving the length of the id 11 it will genarte the same id use before it doesn't change the numbers.
Here is my php code
<?php
function EventRang($length = 10, $type){
switch($type){
case 'int':
//$keyspace = mt_rand(10000000000, 99999999999).date("Ymd").rand();
$keyspace = str_pad(rand(0, pow(10, $length)-1), $length, '0', STR_PAD_LEFT);
break;
case 'char':
$keyspace = date('Fl').'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'str':
$keyspace = time().'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'oid':
//$keyspace = date("Ymd").time().rand().mt_rand(10000000000, 99999999999);
$keyspace = date("Ymd").time().str_pad(rand(0, pow(10, $length)-1), $length, '0', STR_PAD_LEFT);
break;
default:
$keyspace = time().'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
}
$charactersLength = strlen($keyspace);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $keyspace[rand(0, $charactersLength - 1)];
}
return $randomString;
}
?>
this is always the output 2147483647
pow(10,11)exceeds 32-bit numbers2147483647is a magic number that you should learn to recognise; it is the max signed int value for 32-bit PHPoidi want to use the current date and time then add random number at the enddate("Ymd").time()4488765. Please just help me fix it the right way it should be i will have time to look at it and learn more