Module uuid
http://www.ietf.org/rfc/rfc4122.txt is the reference for official UUIDs.
Copyright © 2011-2014 Michael Truog
Version: 1.3.2 Sep 30 2014 14:04:49
------------------------------------------------------------------------
Authors: Michael Truog (mjtruog [at] gmail (dot) com).
http://www.ietf.org/rfc/rfc4122.txt is the reference for official UUIDs.
This implementation provides a version 1 UUID that includes both the
Erlang pid identifier (ID, Serial, Creation) and the distributed Erlang
node name within the 48 bit node ID. To make room for the Erlang pid
identifier, the 48 bits from the MAC address
(i.e., 3 OCI (Organizationally Unique Identifier) bytes and
3 NIC (Network Interface Controller) specific bytes) and
the distributed Erlang node name are bitwise-XORed down to 16 bits.
The Erlang pid is bitwise-XORed from 72 bits down to 32 bits.
The version 3 (MD5), version 4 (random), and version 5 (SHA)
methods are provided as specified within the RFC.
state() = #uuid_state{}
uuid() = <<_:128>>
get_v1(Uuid_state::#uuid_state{}) -> uuid()
get_v1_time() -> non_neg_integer()
The result is an integer in microseconds.
get_v1_time(Uuid_state::os | erlang | #uuid_state{} | uuid()) -> non_neg_integer()
The result is an integer in microseconds.
get_v3(Data::binary()) -> uuid()
get_v3(Namespace::dns | url | oid | x500 | binary(), Data::binary() | iolist()) -> uuid()
get_v3_compat(Data::binary()) -> uuid()
Do not use all bits from the checksum so that the UUID matches external
implementations.
get_v3_compat(Namespace::dns | url | oid | x500 | binary(), Data::binary() | iolist()) -> uuid()
Do not use all bits from the checksum so that the UUID matches external
implementations.
crypto:strong_rand_bytes/1 repeats in the same way as
RAND_bytes within OpenSSL.
crypto:rand_bytes/1 repeats in the same way as
RAND_pseudo_bytes within OpenSSL.
if OpenSSL is configured to use the MD PRNG (default) with SHA1
(in openssl/crypto/rand/md_rand.c),
the collisions are between 2^80 and 2^51
(http://eprint.iacr.org/2008/469.pdf). So, that means "weak" would
repeat ideally every 1.21e24 and at worst every 2.25e15.
if OpenSSL was compiled in FIPS mode, it uses ANSI X9.31 RNG
and would have collisions based on 3DES.
get_v4(X1::strong | weak) -> uuid()
random_wh06_int:uniform/1 repeats every 2.66e36 (2^121) approx.
(see B.A. Wichmann and I.D.Hill, in
'Generating good pseudo-random numbers',
Computational Statistics and Data Analysis 51 (2006) 1614-1622)
a single random_wh06_int:uniform/1 call can provide a maximum of 124 bits
(see random_wh06_int.erl for details)
get_v4_urandom_bigint() -> uuid()
random:uniform/1 repeats every 2.78e13
(see B.A. Wichmann and I.D.Hill, in
'An efficient and portable pseudo-random number generator',
Journal of Applied Statistics. AS183. 1982, or Byte March 1987)
a single random:uniform/1 call can provide a maximum of 45 bits
(currently this is not significantly faster
because multiple function calls are necessary)
explain the 45 bits of randomness:
random:uniform/0 code:
B1 = (A1*171) rem 30269,
B2 = (A2*172) rem 30307,
B3 = (A3*170) rem 30323,
put(random_seed, {B1,B2,B3}),
R = A1/30269 + A2/30307 + A3/30323,
R - trunc(R).
{B1, B2, B3} becomes the next seed value {A1, A2, A3}, so:
R = (918999161 * A1 + 917846887 * A2 + 917362583 * A3) / 27817185604309
Whatever the values for A1, A2, and A3,
(918999161 * A1 + 917846887 * A2 + 917362583 * A3) can not exceed
27817185604309 (30269 * 30307 * 30323) because of the previous modulus.
So, random:uniform/1 is unable to uniformly sample numbers beyond
a N of 27817185604309. The bits required to represent 27817185604309:
1> (math:log(27817185604309) / math:log(2)) + 1.
45.6610416965467
get_v4_urandom_native() -> uuid()
Attempt to only use native integers (Erlang limits integers to 27 bits
before using bigints) to investigate the speed when using HiPE.
get_v5(Data::binary()) -> uuid()
get_v5(Namespace::dns | url | oid | x500 | binary(), Data::binary() | iolist()) -> uuid()
get_v5_compat(Data::binary()) -> uuid()
Do not use all bits from the checksum so that the UUID matches external
implementations.
get_v5_compat(Namespace::dns | url | oid | x500 | binary(), Data::binary() | iolist()) -> uuid()
Do not use all bits from the checksum so that the UUID matches external
implementations.
increment(State::#uuid_state{}) -> #uuid_state{}
The RFC said to increment the clock sequence counter
if the system clock was set backwards. However, erlang:now/0 always
provides increasing time values, so this function is not necessary
when the system clock changes. Since the version 1 node id contains the
Erlang PID ID, Serial, and Creation numbers in a (non-destructive)
bitwise-xor operation, the node id is specific to both the Erlang node
and the Erlang node lifetime (the PID Creation is different after a node
crash). Therefore, it is unclear why this function would be necessary
within this Erlang implementation of v1 UUID generation (if the system
is always running). The only event that seems to require this function's
usage is if the v1 UUID has been stored and retrieved where both actions
occurred at a point with a system clock change inbetween or possibly
on different machines with a large difference in system clocks
(i.e., in some situation that isn't handled by the Erlang VM, so
possibly if an external distribution mechanism was used between
Erlang VMs, not connected with distributed Erlang).
is_uuid(Value::any()) -> boolean()
is_v1(Value::any()) -> boolean()
is_v3(Value::any()) -> boolean()
is_v4(Value::any()) -> boolean()
is_v5(Value::any()) -> boolean()
mac_address() -> [non_neg_integer()]
new(Pid::pid()) -> #uuid_state{}
new(Pid::pid(), Options::os | erlang | [{timestamp_type, os | erlang} | {mac_address, [non_neg_integer()]}]) -> #uuid_state{}
The timestamp can either be based on erlang:now/0 with erlang or
os:timestamp/0 with os. erlang:now/0 will make sure all time values are
increasing, even if the system clock changes. os:timestamp/0 will get the
system clock quickly without modifying the result.
string_to_uuid(X1::string() | binary()) -> uuid()
uuid_to_list(Value::uuid()) -> iolist()
uuid_to_string(Value::uuid()) -> string()
uuid_to_string(Value::uuid(), Option::standard | nodash | list_standard | list_nodash | binary_standard | binary_nodash) -> string() | binary()
Generated by EDoc, Sep 30 2014, 14:04:49.