ruby-changes:10325
From: technorama <ko1@a...>
Date: Thu, 29 Jan 2009 12:20:48 +0900 (JST)
Subject: [ruby-changes:10325] Ruby:r21869 (ruby_1_8): * lib/securerandom.rb: new method SecureRandom#uuid
technorama 2009-01-29 12:20:35 +0900 (Thu, 29 Jan 2009) New Revision: 21869 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21869 Log: * lib/securerandom.rb: new method SecureRandom#uuid Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/lib/securerandom.rb Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 21868) +++ ruby_1_8/ChangeLog (revision 21869) @@ -1,3 +1,7 @@ +Thu Jan 29 12:18:54 2009 Technorama Ltd. <oss-ruby@t...> + + * lib/securerandom.rb: new method SecureRandom#uuid + Wed Jan 28 01:16:50 2009 Masatoshi SEKI <m_seki@m...> * lib/erb.rb (def_erb_method): pass the trim_mode [Feature #1032] Index: ruby_1_8/lib/securerandom.rb =================================================================== --- ruby_1_8/lib/securerandom.rb (revision 21868) +++ ruby_1_8/lib/securerandom.rb (revision 21869) @@ -134,4 +134,14 @@ Math.ldexp(i64 >> (64-Float::MANT_DIG), -Float::MANT_DIG) end end + + # SecureRandom.uuid generates a v4 random UUID. + def self.uuid + str = self.random_bytes(16) + str[6] = (str[6] & 0x0f) | 0x40 + str[8] = (str[8] & 0x3f) | 0x80 + + ary = str.unpack("NnnnnN") + "%08x-%04x-%04x-%04x-%04x%08x" % ary + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/