Re: Re: [RFC][DISCUSSION] Improve uniqid() uniqueness

From: Date: Tue, 04 Oct 2016 10:07:16 +0000
Subject: Re: Re: [RFC][DISCUSSION] Improve uniqid() uniqueness
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-96212@lists.php.net to get a copy of this message
On 4 October 2016 at 02:39, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote: > Hi Leigh, > > On Mon, Oct 3, 2016 at 9:06 PM, Leigh <leight@gmail.com> wrote: >> I'm curious, did you consider using random_int? It already handles >> biasing, and you can reduce the repeated calls to random_bytes. > > Yes. It seemed it might be slower due to number of retries at first, > but I realized that it isn't later. > > It could be something like > > $entropy = random_int(10000000000, 9999999999); > $entropy[1] = '.'; > $uniqid = timestamp . $entropy; > > I don't have particular preference. > > Regards, > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net Since we want to preserve BC entropy = random_int(0, 99999999); uniqid = strpprintf(0, "%s%08x%05x.%08d", prefix, sec, usec, entropy);

« previous php.internals (#96212) next »