Please don't use a random algorithm to generate UUIDs. You're defeating the exact purpose for which they were created.
Yes, 128 bits of randomness are not likely to collide (beating out all lotteries ever), but you know what's better than "not likely to collide"? "Guaranteed by construction to never collide with another UUID, ever"
My apologies, that is a valid uuid4 method. I implied that it wasn't a valid UUID generator, and I was wrong on that point.
I'd still recommend not writing it yourself, and using a tested library implementation, which would provide other variants of UUID like 1, 3, or 5 that have the uniqueness guarantee and are harder to write yourself.
They also make it easier to follow the recommendations in this thread about not using the string representation of a UUID, which takes up more than twice the space in your database.
Please don't use a random algorithm to generate UUIDs. You're defeating the exact purpose for which they were created.
Yes, 128 bits of randomness are not likely to collide (beating out all lotteries ever), but you know what's better than "not likely to collide"? "Guaranteed by construction to never collide with another UUID, ever"
GUIDs are designed to be unique, not random
Hey, thanks a lot for your reply @jakebman . What's your suggestion for substituting randomness with uniqueness ?
My apologies, that is a valid uuid4 method. I implied that it wasn't a valid UUID generator, and I was wrong on that point.
I'd still recommend not writing it yourself, and using a tested library implementation, which would provide other variants of UUID like 1, 3, or 5 that have the uniqueness guarantee and are harder to write yourself.
They also make it easier to follow the recommendations in this thread about not using the string representation of a UUID, which takes up more than twice the space in your database.
laravel.com/docs/5.6/migrations#cr...
You should check this library out: github.com/ramsey/uuid. It's very popular.
That package is required by default by Laravel Framework so it is already present.