PHP Classes

generate unique id by 11 digi number: generate unique id

Recommend this page to a friend!
  All requests RSS feed  >  generate unique id by 11 digi number  >  Request new recommendation  >  A request is featured when there is no good recommended package on the site when it is posted. Featured requests  >  No recommendations No recommendations  

generate unique id by 11 digi number

Edit

Picture of Mohamed Riyas by Mohamed Riyas - 7 years ago (2018-02-08)

generate unique id

This request is clear and relevant.
This request is not clear or is not relevant.

+1

I need to generate 11 digit unique id, need need duplicate. how can i generate?

  • 2 Clarification requests
  • 2. Picture of zinsou A.A.E.Moïse by zinsou A.A.E.Moïse - 7 years 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. Picture of zinsou A.A.E.Moïse by zinsou A.A.E.Moïse - 7 years 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>';

      Ask clarification

      1 Recommendation

      Riddler: Generate passwords according to given criteria

      This class can generate passwords according to given criteria.

      It can generate text strings that may vary in different aspects using specific classes that define criteria for the characters of the text string.

      Currently it provides classes for defining criteria that can be of type contracts, dictionaries, formats, and occurrences.
      This recommendation solves the problem.
      This recommendation does not solve the problem.

      +1

      Picture of DeGraciaMathieu by DeGraciaMathieu package author package author Reputation 90 - 7 years 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
      : 
      :