From: Aaron Smith Date: 2007-03-09T10:38:10+09:00 Subject: Re: generate UUID Eden Li wrote: > He probably meant to_s(16), not to_a(16). Anyway, rand_hex_2 won't > zero-pad, so you might want to replace the to_s with a format > operator: > > def rand_hex_3(l) > "%0#{n}x" % rand(1 << n*4) > end > > def rand_uuid > [8,4,4,4,12].map {|n| rand_hex_3(n)}.join('-') > end > > puts rand_uuid cool, thanks. just to clarify. couple variable names needed changing def rand_hex_3(l) "%0#{l}x" % rand(1 << l*4) end def rand_uuid [8,4,4,4,12].map {|n| rand_hex_3(n)}.join('-') end puts rand_uuid -- Posted via http://www.ruby-forum.com/.