Page 1 of 1

Unique ID generaion script

Posted: Fri Feb 05, 2010 12:49 am
by shreehart
script which will genrate 5-digit hexadecimal number?

Re: Unique ID generaion script

Posted: Fri Feb 05, 2010 2:27 am
by dejvos
What about:

Code: Select all

 
srand(time());
$x = dechex(rand(1,16^5)-1);
$zero = "";
if(strlen($x) < 5)
for($i = strlen($x); $i<=5;$i++)
$zero .= "0";
 
$result = $zero.$x;
 
That could works.

Re: Unique ID generaion script

Posted: Fri Feb 05, 2010 2:29 am
by dejvos
Actually I forgot to mention that the number will be pseudo-random. If you want a real random number, you need somthing else then ordinary computer.

Read here: http://www.random.org/

Re: Unique ID generaion script

Posted: Fri Feb 05, 2010 4:19 am
by VladSun
dejvos wrote:What about:

Code: Select all

 
srand(time());
... 
It's vulnerable to bruteforce seed attack, which allows the attacker to predict the generated "random" strings.

We've discussed this recently - viewtopic.php?f=34&t=112311

Re: Unique ID generaion script

Posted: Fri Feb 05, 2010 12:05 pm
by pickle
shreehart wrote:script which will genrate 5-digit hexadecimal number?
Yes, they exist. Did you have any particular problem you needed help with? That's what we tend to do here - "help" rather than "do your work for you"