Welcome Guest, Not a member yet? Register   Sign In
How random is the random string function?
#1

[eluser]ShoeLace1291[/eluser]
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?
#2

[eluser]LuckyFella73[/eluser]
There are different functions in PHP generating random results. Which one
do you use?

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

http://php.net/manual/de/function.mt-rand.php
#3

[eluser]boltsabre[/eluser]
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.
#4

[eluser]niki_mihaylov[/eluser]
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
#5

[eluser]Pert[/eluser]
You can use PHP uniqid()




Theme © iAndrew 2016 - Forum software by © MyBB