All requests | > | generate unique id by 11 digi number | > | Request new recommendation | > | Featured requests | > | No recommendations |
by Mohamed Riyas - 3 days ago (2018-02-08)
0 | I need to generate 11 digit unique id, need need duplicate. how can i generate? |
2. by zinsou A.A.E.Moïse - 3 days ago (2018-02-08) Reply
with the first function you got 99999999999 unique ids and 1/99999999999 chance for each id to appear.I don't know anything about a viable way to achieve the goal of getting unique ids with only digit except if you use auto increment with left padding like in function 2 to always get the same length for your ids while keeping uniqueness...
<?php function uniq_digit_id($max=11){//more max is low less you got uniqueness
$i=0;
$uniq_digit_id='';
while($i<$max){
$uniq_digit_id .=rand(0,9);
$i++;
}
return $uniq_digit_id;
}
function uniq_digit_id2($max=11,$data='uniq_digit_id2.txt'){
$i=0;
$maxnumber='';
while($i<$max){
$maxnumber .='9';
$i++;
}
if(file_exists($data)){
$id=trim(file_get_contents($data));
if(strlen($id)==$max){
/*you must use only one file per counter otherwise the file will be formatted
to restart counter according to $max arg */
if($id==$maxnumber) return false;/*if the max number with the length $max
is reached the response will always be false; so be sure to test the value before use it*/
$id++;
file_put_contents($data,($id=str_pad($id,$max,'0',STR_PAD_LEFT)));
return $id;
}else{
$id=0;
file_put_contents($data,($id=str_pad($id,$max,'0',STR_PAD_LEFT)));
return $id;
}
}else{
$id=0;
file_put_contents($data,($id=str_pad($id,$max,'0',STR_PAD_LEFT)));
return $id;
}
}
echo '<pre>'; var_dump(uniq_digit_id(),uniq_digit_id(),uniq_digit_id(),uniq_digit_id(),uniq_digit_id()); var_dump(uniq_digit_id2(),uniq_digit_id2(),uniq_digit_id2(),uniq_digit_id2(),uniq_digit_id2()); echo '</pre>';
1. by zinsou A.A.E.Moïse - 3 days ago (2018-02-08) Reply
with the first function you got 99999999999 unique ids and 1/99999999999 chance for each id to appear.I don't know anything about a viable way to achieve the goal of getting unique ids with only digit except if you use auto increment with left padding like in function 2 to always get the same length for your ids while keeping uniqueness...
<?php function uniq_digit_id($max=11){//more max is low less you got uniqueness
$i=0;
$uniq_digit_id='';
while($i<$max){
$uniq_digit_id .=rand(0,9);
$i++;
}
return $uniq_digit_id;
}
function uniq_digit_id2($max=11,$data='uniq_digit_id2.txt'){
$i=0;
$maxnumber='';
while($i<$max){
$maxnumber .='9';
$i++;
}
if(file_exists($data)){
$id=trim(file_get_contents($data));
if(strlen($id)==$max){
/*you must use only one file per counter otherwise the file will be formatted
to restart counter according to $max arg */
if($id==$maxnumber) return false;/*if the max number with the length $max
is reached the response will always be false; so be sure to test the value before use it*/
$id++;
file_put_contents($data,($id=str_pad($id,$max,'0',STR_PAD_LEFT)));
return $id;
}else{
$id=0;
file_put_contents($data,($id=str_pad($id,$max,'0',STR_PAD_LEFT)));
return $id;
}
}else{
$id=0;
file_put_contents($data,($id=str_pad($id,$max,'0',STR_PAD_LEFT)));
return $id;
}
}
echo '<pre>'; var_dump(uniq_digit_id(),uniq_digit_id(),uniq_digit_id(),uniq_digit_id(),uniq_digit_id()); var_dump(uniq_digit_id2(),uniq_digit_id2(),uniq_digit_id2(),uniq_digit_id2(),uniq_digit_id2()); echo '</pre>';
0 | by DeGraciaMathieu 75 - 2 hours ago (2018-02-12) Comment Hello, You can use this package like this <?php require 'vendor\autoload.php'; use DeGraciaMathieu\Riddler\Password; use DeGraciaMathieu\Riddler\Dictionaries; use DeGraciaMathieu\Riddler\Occurrences; $password = new Password(); $password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(11)); $password->generate(); // 16422597895 |
Recommend package | |
|