?

Log in

No account? Create an account
v4 UUIDs - Michael Truog
okeuday
v4 UUIDs
After updating the Erlang uuid implementation to fix various bugs, I added uuid:get_v4_urandom/0 function to utilize the 2006 Wichmann-Hill algorithm for generating uniform pseudo-random numbers. The main reason to utilize this algorithm, is for the 124 maximum bits of randomness when compared with the 45 maximum bits of randomness available with the normal Erlang OTP random module. Not just the amount of pseudo-randomness is better, but also the period is increased, to be more competitive with the Erlang OTP crypto module usage (i.e., OpenSSL usage). There are likely to be better pseudo-randomness generators available, but this particular choice seemed like a good fit for Erlang, due to Erlang's native big integer support. The main goal is to provide the pseudo-randomness within pure Erlang source code, without the need for C/C++ integration. I consider the uuid:get_v4_urandom/0 function to be experimental, but I look forward to its use after more testing. The tests show both the speed of pseudo-randomness and uuid creation, to see how the various functions compare. The benchmark was ran (with R14B04, without HiPE) on an AMD Phenom 9950 Quad-Core (64 bit) running Linux 2.6.32-23-generic (Ubuntu) (i.e., "the older dependencies" machine):
TEST uuid_creation
N == 100000 (10 runs)
                  v1 get:    79487.3 us (  1.0)
                  v3 get:   131336.8 us (  1.7)
    v4 crypto strong get:   201665.8 us (  2.5)
      v4 crypto weak get:   201813.2 us (  2.5)
    v4 random bigint get:   209130.1 us (  2.6)
    v4 random native get:   322730.1 us (  4.1)
  v4 random_wh06_int get:   154083.6 us (  1.9)
                  v5 get:   152191.5 us (  1.9)

TEST pseudo_randomness
N == 10000 (10 runs)
crypto:rand_uniform/ get:    61465.2 us ( 27.1)
        erlang:now/0 get:     2781.2 us (  1.2)
      os:timestamp/0 get:     2264.4 us (  1.0)
    random:uniform/1 get:     6971.9 us (  3.1)
random_wh06_int:unif get:    13464.4 us (  5.9)
Leave a comment