Generating random numbers
am 17.04.2008 01:00:21 von joefazee
------=_Part_4720_2160192.1208386821838
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
What is the best way to generating random numbers and you are sure that the
script will never generate the generated ones?
I`m using mysql database, but this out of SQL AUTO_INCREMENT stuff, I need a
real random generator that will never generate what has been generated.
------=_Part_4720_2160192.1208386821838--
Re: Generating random numbers
am 17.04.2008 02:05:19 von Trevor Gryffyn
Is the most important thing to be random or to be unique? If you need
unique, you can use a timestamp including microseconds. Maybe using
something like microtime():
http://us.php.net/manual/en/function.microtime.php
The only other way you're probably going to guarentee that you don't repeat
numbers is to keep a list of what's been used and compare against it.
Otherwise, there's always going to be a slim chance you'll repeat a number.
What do you plan on using it for? Maybe someone can give a better
recommendation for what you need. And will this number be generated by
PHP or the database? Or can it be either?
-TG
----- Original Message -----
From: "A. Joseph"
To: "Evert Lammerts"
Cc: "php-db@lists.php.net"
Date: Thu, 17 Apr 2008 00:00:21 +0100
Subject: [PHP-DB] Generating random numbers
> What is the best way to generating random numbers and you are sure that the
> script will never generate the generated ones?
>
> I`m using mysql database, but this out of SQL AUTO_INCREMENT stuff, I need a
> real random generator that will never generate what has been generated.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Generating random numbers
am 17.04.2008 03:10:45 von dmagick
TG wrote:
> Is the most important thing to be random or to be unique? If you need
> unique, you can use a timestamp including microseconds. Maybe using
> something like microtime():
> http://us.php.net/manual/en/function.microtime.php
>
> The only other way you're probably going to guarentee that you don't repeat
> numbers is to keep a list of what's been used and compare against it.
> Otherwise, there's always going to be a slim chance you'll repeat a number.
>
> What do you plan on using it for? Maybe someone can give a better
> recommendation for what you need. And will this number be generated by
> PHP or the database? Or can it be either?
There's also http://au.php.net/uniqid - you could even use a different
prefix for each call.
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php