Related question: is there a select query that generates a sequence of numbers from 1 till 10 (or 100 or 1000)? It is unlikely though that you will generate the same hash twice until you have generated a lot of them particularly if the original values only vary by a small amount each time - since the purpose of a hash is that a minor change to the original will produce an entirely different hash - you would still need to test if it has already been used but simply restarting the process if inserting the hash into the database fails wouldd be the simplest way of handling it (assuming that you use the value as the primary key - which is appropriate as it is supposed to be unique). Just add â-XXXâ to the end of your current format and youâve covered all the characters. To generate a sequence of n-digit pseudorandom numbers, an n-digit starting value is created and squared, producing a 2n-digit number. The thing is, itâs based on time since epoch. I can generate the code by one way or another usin chr() etc. Now create a function getFiveDigitId( $numericId) which will return the string of five digit: function getFiveDigitId( $numericId){ $id = $numericId/100000; // will give you 0.00001 $strId = strVal($id); // convert to string if(startsWith($strId, "0. If the OP doesn't care about repeats in the sequence and those three numbers were always the ones to be excluded then that technique would work. We've created a simple function where you can specify start number, count and how many digits the generated numbers should be. Generate Weird Number Sequence. There are three different functions for generating random numbers in PHP. Create a list of Ulam numbers. Generating incremented number is not a big thing you can use database table or a static integer variable which will give you a number +1 to its previous value. Tip: If you want a random integer between 10 and 100 (inclusive), use rand (10,100). As you mention you need a number which starts from 000 like but a integer variable always ignore the number starts from 0, so first thing you need to hold it as a string may be. 1. tinyint- Range 0 to 255 2. smallint- Range -32,768 to 32,767 3. int- Range -2,147,483,648 to 2,147,483,647 4. bigint- Range -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 5. decimal and numericwith a scale of 0. To generate a random number between 1 and 100, do the same, but with 100 in the second field of the picker.