MyBB Community Forums

Full Version: how many unique results you can get with rand() ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am wondering how much unique results can be accomplished in php by using

rand();

and by using

$num=5;
md5($num.rand());
getrandmax() and you know. May be as low as 32767 on some platforms. Even on Linux 64bit it's only 2^31

If it's unique you need, uniqid() may work
Now how about this one ? how many unique results will the below hash will generate ?
$num=5;
md5($num.rand().uniqid());

Ideally 2^128 since md5 is a 128 bit hash
<?php echo PHP_INT_MAX; ?>

That many.

(2012-09-23, 11:55 AM)sunjava1 Wrote: [ -> ]Now how about this one ? how many unique results will the below hash will generate ?
$num=5;
md5($num.rand().uniqid());


If uniqid() is already unique, what's the point of hashing and adding a 5? It won't be unique anymore since uniqid() is unique and md5() is not.