RE: [PHP] unique random id

From: Date: Thu, 19 Jun 2003 12:15:36 +0000
Subject: RE: [PHP] unique random id
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-152148@lists.php.net to get a copy of this message
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, 1000000000000000) ) ) { # 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:php@sheridan-phoenix.com] Verzonden: donderdag 19 juni 2003 10:47 Aan: php-general@lists.php.net Onderwerp: [PHP] unique random id How do i generate a unique random number? thanks awlad

« previous php.general (#152148) next »