ruby-changes:10324
From: technorama <ko1@a...>
Date: Thu, 29 Jan 2009 12:20:42 +0900 (JST)
Subject: [ruby-changes:10324] Ruby:r21868 (trunk): * lib/securerandom.rb: new method SecureRandom#uuid
technorama 2009-01-29 12:20:26 +0900 (Thu, 29 Jan 2009) New Revision: 21868 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21868 Log: * lib/securerandom.rb: new method SecureRandom#uuid Modified files: trunk/ChangeLog trunk/lib/securerandom.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 21867) +++ ChangeLog (revision 21868) @@ -1,3 +1,7 @@ +Thu Jan 29 12:18:54 2009 Technorama Ltd. <oss-ruby@t...> + + * lib/securerandom.rb: new method SecureRandom#uuid + Thu Jan 29 11:22:19 2009 NAKAMURA Usaku <usa@r...> * ext/socket/raddrinfo.c (inspect_sockaddr): if defined AF_INET6, Index: lib/securerandom.rb =================================================================== --- lib/securerandom.rb (revision 21867) +++ lib/securerandom.rb (revision 21868) @@ -167,6 +167,16 @@ 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 + # Following code is based on David Garamond's GUID library for Ruby. def self.lastWin32ErrorMessage # :nodoc: get_last_error = Win32API.new("kernel32", "GetLastError", '', 'L') -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/