Forum: Ruby generate uuid

3083ca8f0496edaac2fa10c20630d0bc?d=identicon&s=25 Newb Newb (newb)
on 2008-08-28 10:48
How Can I  generate uuid ? any references or Ideas could You people
suggest.I have not even heard about it?
6a6d3bbc06625f2043bdb5d79fa8512b?d=identicon&s=25 geo ssscripting (vhaerun)
on 2008-08-28 12:02
Newb Newb wrote:
> How Can I  generate uuid ? any references or Ideas could You people
> suggest.I have not even heard about it?

http://en.wikipedia.org/wiki/Uuid#Ruby
34a7615f38496a5dafbb3e6b721c435e?d=identicon&s=25 Mohit Sindhwani (Guest)
on 2008-08-31 10:46
(Received via mailing list)
Lex Williams wrote:
> Newb Newb wrote:
>
>> How Can I  generate uuid ? any references or Ideas could You people
>> suggest.I have not even heard about it?
>>
>
> http://en.wikipedia.org/wiki/Uuid#Ruby
>
In Windows, you can use this code.  I'm not sure where I found this
from, so I can't tell you who to thank :P

require 'Win32API'

@uuid_create = Win32API.new('rpcrt4', 'UuidCreate', 'P', 'L')

def new_guid
  result = ' ' * 16
  @uuid_create.call(result)
  a, b, c, d, e, f, g, h = result.unpack('SSSSSSSS')
  sprintf('{%04X%04X-%04X-%04X-%04X-%04X%04X%04X}', a, b, c, d, e, f, g,
h)
end

puts new_guid


Cheers,
Mohit.
8/31/2008 | 2:28 PM.
1bac2e65d64faf472cf2ebc94f0f5ee0?d=identicon&s=25 Ara Howard (ahoward)
on 2008-08-31 18:13
(Received via mailing list)
On Aug 28, 2008, at 2:43 AM, Newb Newb wrote:

> How Can I  generate uuid ? any references or Ideas could You people
> suggest.I have not even heard about it?


not mine, but here's a copy:

   http://s3.amazonaws.com/drawohara.com.ruby/uuid.rb


a @ http://codeforpeople.com/
666b4e17b4bb0e2d999037a25f65a7cb?d=identicon&s=25 Heesob Park (phasis)
on 2008-09-01 03:18
(Received via mailing list)
2008/8/28 Newb Newb <hema@angleritech.com>:
> How Can I  generate uuid ? any references or Ideas could You people
> suggest.I have not even heard about it?

You get get UUID on the WEB like this:

require 'open-uri'
uuid = open('http://www.famkruithof.net/uuid/uuidgen').
          read.scan(/<h3>([-[:alnum:]]+)<\/h3>/).to_s
puts uuid

Regards,

Park Heesob
6076c22b65b36f5d75c30bdcfb2fda85?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2008-09-01 23:35
(Received via mailing list)
On Aug 31, 2008, at 6:12 PM, Heesob Park wrote:

>
> Regards,
>
> Park Heesob


One thing I;ve found is that all of the UUID generators are painfully
slow if you need to make a bunch of uuid's. Here is a way to cheat,
but do so at your own risk as this is not garaunteed to be as safe as
a true uuid but in practice works very well.

    def fast_token
      values = [
        rand(0x0010000),
        rand(0x0010000),
        rand(0x0010000),
        rand(0x0010000),
        rand(0x0010000),
        rand(0x1000000),
        rand(0x1000000),
      ]
      "%04x%04x%04x%04x%04x%06x%06x" % values
    end


Cheers-
-Ezra
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2008-09-01 23:54
(Received via mailing list)
On Sep 1, 2008, at 4:27 PM, Ezra Zygmuntowicz wrote:

>>        read.scan(/<h3>([-[:alnum:]]+)<\/h3>/).to_s
>> puts uuid
>>
>> Regards,
>>
>> Park Heesob
>
>
> One thing I;ve found is that all of the UUID generators are
> painfully slow if you need to make a bunch of uuid's.

My favorite trick is:

   uuid = `uuidgen`.strip

It has always been fast enough for my needs.

James Edward Gray II
833348fb139ec4d62508eb9f0e28ac06?d=identicon&s=25 Tommy Nordgren (Guest)
on 2008-09-02 01:02
(Received via mailing list)
On 1 sep 2008, at 23.48, James Gray wrote:

>>> require 'open-uri'
>> painfully slow if you need to make a bunch of uuid's.
>
> My favorite trick is:
>
>  uuid = `uuidgen`.strip
>
> It has always been fast enough for my needs.
>
> James Edward Gray II
>
>
       The variation I use is uuid = "x_#{`uuidgen`.strip}"

The advantage is that the generated uuid is always suitable as an xml ID
5a837592409354297424994e8d62f722?d=identicon&s=25 Ryan Davis (Guest)
on 2008-09-02 01:46
(Received via mailing list)
On Sep 1, 2008, at 14:48 , James Gray wrote:

> My favorite trick is:
>
>  uuid = `uuidgen`.strip
>
> It has always been fast enough for my needs.

that's nice. 10k real uuids in 1 minute is perfectly acceptable for
almost all cases. thanks.

% ./blah.rb 10000
# of iterations = 10000
                           user     system      total        real
null_time             0.000000   0.000000   0.000000 (  0.001486)
ezra                  0.200000   0.000000   0.200000 (  0.201678)
uuidgen               1.160000  12.630000  58.190000 ( 56.684045)

----

puts "# of iterations = #{max}"
Benchmark::bm(20) do |x|
   x.report("null_time") do
     for i in 0..max do
       # do nothing
     end
   end

   x.report("ezra") do
     for i in 0..max do
       fast_token
     end
   end

   x.report("uuidgen") do
     for i in 0..max do
       `uuidgen`.strip
     end
   end
end
1bac2e65d64faf472cf2ebc94f0f5ee0?d=identicon&s=25 Ara Howard (ahoward)
on 2008-09-02 02:21
(Received via mailing list)
On Sep 1, 2008, at 5:38 PM, Ryan Davis wrote:

> almost all cases. thanks.
> puts "# of iterations = #{max}"
>    end
>  end
>
>  x.report("uuidgen") do
>    for i in 0..max do
>      `uuidgen`.strip
>    end
>  end
> end
>
>


cfp:~ > cat a.rb
require 'open-uri'

uri = 'http://s3.amazonaws.com/drawohara.com.ruby/uuid.rb'

eval open(uri).read

a = Time.now.to_f

( n = 1000 ).times{ uuid = UUID.string }

b = Time.now.to_f

elapsed = b - a

puts "uuid/min : #{ n / elapsed * 60 }"



cfp:~ > ruby a.rb
uuid/min : 113947.784509223



it's kinda a POS, but with the addition of macaddr and a few other
tidbits (state using AR for instance) it's pretty dang good : 10 times
faster and pure ruby.






a @ http://codeforpeople.com/
391f9b787cdc12aa2c179713f5103e3a?d=identicon&s=25 Ilan Berci (iberci)
on 2008-09-02 18:09
Newb Newb wrote:
> How Can I  generate uuid ? any references or Ideas could You people
> suggest.I have not even heard about it?


sudo gem install guid


irb(main):001:0> require 'guid'
=> true
irb(main):002:0> Guid.new
=> b93e5a88-acf7-be64-af0b-6de00bd83fd3
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.