Generate uuid

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

···

--
Posted via http://www.ruby-forum.com/.

Newb Newb wrote:

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

···

--
Posted via http://www.ruby-forum.com/\.

not mine, but here's a copy:

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

a @ http://codeforpeople.com/

···

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?

--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama

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

···

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?

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

···

--
Posted via http://www.ruby-forum.com/\.

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?
    
Universally unique identifier - Wikipedia
  

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 :stuck_out_tongue:

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.

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(0x1000000),
      ]
      "%04x%04x%04x%04x%04x%06x%06x" % values
    end

Cheers-
-Ezra

···

On Aug 31, 2008, at 6:12 PM, Heesob Park wrote:

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&#39;\).
        read.scan(/<h3>([-[:alnum:]]+)<\/h3>/).to_s
puts uuid

Regards,

Park Heesob

My favorite trick is:

   uuid = `uuidgen`.strip

It has always been fast enough for my needs.

James Edward Gray II

···

On Sep 1, 2008, at 4:27 PM, Ezra Zygmuntowicz wrote:

On Aug 31, 2008, at 6:12 PM, Heesob Park wrote:

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&#39;\).
       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.

The variation I use is uuid = "x_#{`uuidgen`.strip}"

The advantage is that the generated uuid is always suitable as an xml ID

···

On 1 sep 2008, at 23.48, James Gray wrote:

On Sep 1, 2008, at 4:27 PM, Ezra Zygmuntowicz wrote:

On Aug 31, 2008, at 6:12 PM, Heesob Park wrote:

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&#39;\).
      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

------------------------------------------------------
"Home is not where you are born, but where your heart finds peace" -
Tommy Nordgren, "The dying old crone"
tommy.nordgren@comhem.se

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)

···

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.

----

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

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

uri = 'http://s3.amazonaws.com/drawohara.com.ruby/uuid.rb&#39;

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/

···

On Sep 1, 2008, at 5:38 PM, Ryan Davis wrote:

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

--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama