sneakyimp;11046793 wrote:The function [man]uniqid[/man] is perhaps the simplest way to generate one in PHP.
Two possible problems with that is that it is not random, as it is derived from the current time; and it does not return a decimal integer, if that is what is needed (it returns something like a hexadecimal string concatenated with an integer for the microseconds. Depending on what the OP really needs it for, those may or may not be issues. I've used it in the past to generate sort of random-looking tokens that are highly unlikely to collide, with something like:
$token = md5(uniqid('', true));