2012-09-23, 10:38 AM
2012-09-23, 10:44 AM
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
If it's unique you need, uniqid() may work
2012-09-23, 11:55 AM
Now how about this one ? how many unique results will the below hash will generate ?
$num=5;
md5($num.rand().uniqid());
2012-09-23, 12:04 PM
Ideally 2^128 since md5 is a 128 bit hash
2012-09-23, 11:57 PM
<?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.