One way to use /dev/urandom
is to use the uiniqid function, which should suit your needs.
However, if you need true random numbers, you are better off using /dev/random
, since /dev/urandom
is still a pseudo-random number generator that uses /dev/random
for seed values.
Access to a stream of random numbers is not so difficult.
<?php $r = unpack('v*', fread(fopen('/dev/random', 'r'),16)); $uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', $r[1], $r[2], $r[3], $r[4] & 0x0fff | 0x4000, $r[5] & 0x3fff | 0x8000, $r[6], $r[7], $r[8]); ?>
Obviously, this is not production code.
source share