Click here to Skip to main content
16,007,932 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how do i create a customized random Alphanumerical digit on php. am designing a receipt and i want to integrate it on the receipt. the alphanumerical number should look like this TEB00100020 to infinity and should be stored into the database through a textfield.

Thanks
Posted

1 solution

Use mt_rand(min,max) to generate values.

For alphabetic values, use it in a loop three times with a range that spans 1 through 26 (or ascii value equivalents of A through Z). In either case, cunningly create character values out of them.

Then, loop through it ten times with the range (0, 9). Loop through for as many digits as you wish.

So - it should look something like:
$randString = ''; // initialize to empty

for($i=0; $i<3; $i++)
  $randString .= (your chars); // appending your three characters
for($i=0; $i<8; $i++)
  $randString .= Use mt_rand(0, 9); // appending your eight digits
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900