Re: [PHP-DB] Generating random numbers

[email protected] (Chris)
Newsgroups php.db
Message-ID <[email protected]>
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/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.