Reputation: 4648
does anyone know a simple way to generate a random 64 bit number using PHP? It would be best if it doesn't rely on any extensions if possible.
Upvotes: 2
Views: 3836
Reputation: 116110
Generate a bunch of smaller (16 bits) random numbers using mt_rand and combine them. This approach is also used in this UUID example on php.net.
Upvotes: 3
Reputation: 97571
This?
rand(0, 18446744073709551615)
On some platforms (such as Windows), getrandmax() is only 32768. If you require a range larger than 32768, specifying min and max will allow you to create a range larger than this, or consider using mt_rand() instead.
Upvotes: 3
Reputation: 78443
Fetch 8 random bytes from /dev/urandom or some equivalent source.
Upvotes: 4