By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,116 Members | 1,319 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,116 IT Pros & Developers. It's quick & easy.

How can i generate a random pin about 8 alphanumeric pins..?

P: 6
i dont know how to generate pins..that will be inserted on the registration page ..that if the registration was pass it will be put on the field of `pins`.. thanks in advance ..
Feb 5 '12 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 100+
P: 465
One way is a simple function that takes the length you want and the acceptable characters, something like this

Expand|Select|Wrap|Line Numbers
  1. function GenerateRandom($length, $charset='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
  2. {
  3.     $randString = '';
  4.     $count = strlen($charset);
  5.     while ($length--) 
  6.     {
  7.         $randString .= $charset[mt_rand(0, $count-1)];
  8.     }
  9.     return $randString;
  10. }
Hope that helps
Feb 5 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.