ruby - SecureRandom.uuid vs UUID gem -
is there difference between ruby's securerandom.uuid (ruby 1.9.3) , uuid gem? uuid gem "old" way of doing things?
from docs gather gem more "safe" real unique uuid while securerandom.uuid more of random string has larger chance of not being unique. in addition uuid seems allow file-based persistence assist this.
so hoping hear people more insight me this.
there several methods of generating uuid.
wikipedia job of listing them out.
http://en.wikipedia.org/wiki/universally_unique_identifier
v4 uuids:
the key idea random, is hard generate when relating encryption. random number generators math formula need random , works fine applications. many programs use $pid | time, generate random seed.
which, not promising... know time request generated , there 65,534 pids. can figure out random seed that.
so, if seed uuidv4 number generator @ exact same time (same second) $pid | time() across 100 machines pid numbers, have (i guess) 100/65536 chance of duplication. done this
for mach in `cat machine_list`; ; ssh $mach -c "restart something" & ; done securerandom:
the code securerandom, tries openssl, /dev/urandom, win32...
when reading /dev/urandom, it's random, if there isn't enough chaos in system, urandom make stuff supply random data. when reading /dev/random, its' random, , if there isn't enough chaos, /dev/random block.
uuid:
the uuid gem uses rand()
r = [rand(0x100000000)].pack "n"
for mac address.
uuid not supply v4 uuids :)
practically, if ever have md5 or uuid collision buying lottery ticket!
Comments
Post a Comment