Even though the top answer is practically correct, it's not theoretically correct.
Your question doesn't have a perfect answer either.
Security relies on unbiased, unpredictable, true randomness. But something which is truly random can always repeat, or it wouldn't be random. A million-sided die could land on the same number a million times in a row, the probability of that happening is just very small.
The strength of UUIDv4 is that the probability of getting the same ID twice (collision) is astronomically small, the "pick the same atom from a galaxy twice" kind of small.
Any attempt to add uniqueness will in fact decrease security. You could add a microsecond timestamp or auto-incrementing value and a millimeter precision spatial coordinate to guarantee uniqueness. But then you add information about where and how and in what order the ID was created...
Again, for all practical purposes, it's safe to use UUIDv4 as a safe and unique identifier.
Also realize that md5
, sha1
, uniqid
, etc are not perfect by themselves, and combining them in random ways does not necessarily decrease collision or increase security. Hashing functions are at best as unique as the thing you are hashing, and usually they decrease uniqueness.
The answer always lies in randomness plus length.