Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ramsey/uuid version 4 use "true" or pseudo-random numbers?

Tags:

php

uuid

random

I'm using ramsey/uuid in my project. I'm creating new data entities with uuid4, which generates random UUIDs:

Uuid::uuid4();

But I'm using this approach while bulk importing many thousands of data too. Now I'm worrying about the entropy pool of my system: does uuid4 use a "true" random number which will deplete my entropy pool at some time? Or will it use pseudo-random numbers and I don't have to worry about?

Thanks a lot!

like image 505
Michael Hirschler Avatar asked Dec 06 '25 03:12

Michael Hirschler


1 Answers

By default, it generates UUIDs from the random_bytes() function in PHP 7, or the polyfill from the paragonie/random_compat library in PHP 5. So its UUIDs are as random as the response from those functions. See the RandomBytesGenerator class.

It depends what you're doing with the UUIDs as to whether that randomness is good enough.

like image 197
Dan Blows Avatar answered Dec 11 '25 13:12

Dan Blows



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!