18

What is the difference between the following two functions

Are they both the same behind the scenes? Any performance impacts on using one?

NO WAR WITH RUSSIA
  • 54,954
  • 34
  • 200
  • 411

1 Answers1

18

Are they the same?

No.

The Postgres documetation for uuid-ossp suggests using gen_random_uuid() If you only need randomly-generated (version 4) UUIDs,

The uuid-ossp extension also provides other types of UUID (such as mac-addresses based)

The difference?

I looked at the source and discovered that

  • uuid_generate_v4() uses arc4random to determine the random part.

  • gen_random_uuid() uses fortuna instead.

Other than that they do the same job.

Basil Bourque
  • 8,776
  • 14
  • 46
  • 78
Jasen
  • 2,350
  • 9
  • 14
  • 3
    arc4random vs. fortuna, why should you care? As best I can tell arc4random *could* have some vulnerabilities. Fortuna appears to be more secure. https://en.wikipedia.org/wiki/Fortuna_(PRNG) https://en.wikipedia.org/wiki/RC4#RC4-based_random_number_generators https://security.stackexchange.com/questions/85601/is-arc4random-secure-enough/172905#172905 – HairOfTheDog Jun 25 '21 at 02:54