RE: [PHP] unique random id

2003-06-19 Thread esctoday.com | Wouter van Vliet
check the manual on the rand(); function ..

If you want to make sure this number is unique .. create an array storing
all the numbers you've used once and do some nice tricks with a loop and
stuff untill you get a nice unique random number ... like this:

?php
$UsedValues = Array();

function GetRandomNumber() {
while(  $Rand = round( rand(0, 1000) )  ) {
# Using round() to round the float returned by rand()

if (!in_array($Rand, $UsedValues)) return $Rand;
array_push($UsedValues, $Rand);
}
};

?

-Oorspronkelijk bericht-
Van: Awlad Hussain [mailto:[EMAIL PROTECTED]
Verzonden: donderdag 19 juni 2003 10:47
Aan: [EMAIL PROTECTED]
Onderwerp: [PHP] unique random id


How do i generate a unique random number?

thanks

awlad





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] unique random id

2003-06-19 Thread CPT John W. Holmes
 How do i generate a unique random number?

You can use rand(), but there's no guarantee it'll be unique unless you
remember every number you've ever generated

---John Holmes...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] unique random id

2003-06-19 Thread Don Read

On 19-Jun-2003 Awlad Hussain wrote:
 How do i generate a unique random number? 
 

http://www.php.net/manual/en/function.uniqid.php

Regards,
-- 
Don Read   [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php