• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How random is the random string function?

I use the random string function to generate activation codes for my members' accounts. What are the chances that this function will generate the same string twice?

There are different functions in PHP generating random results. Which one
do you use?

I would prefer the "mt_rand()" function over "rand()".


If you are really worried about this, and it is absolutely critical that activation codes are unique can also append/prepend a unix timestamp to your random string when you create it, virtually impossible for duplication if your random string in 10+ characters.

Just use user ID from the database - this way there is no chance of getting same code twice. Also you can add timestamp if generating more codes for same user in future. Then you can Md5 or use other sexy function to serve it Smile

You can use PHP uniqid()

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.