How Can I generate uuid ? any references or Ideas could You people
suggest.I have not even heard about it?
Newb N. wrote:
How Can I generate uuid ? any references or Ideas could You people
suggest.I have not even heard about it?
Lex W. wrote:
Newb N. wrote:
How Can I generate uuid ? any references or Ideas could You people
suggest.I have not even heard about it?
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
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.
2008/8/28 Newb N. [email protected]:
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(‘UUID (GUID) Generator on the WEB’).
read.scan(/
([-[:alnum:]]+)</h3>/).to_s
puts uuid
Regards,
Park H.
On Aug 31, 2008, at 6:12 PM, Heesob P. wrote:
Regards,
Park H.
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
On Aug 28, 2008, at 2:43 AM, Newb N. 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:
On 1 sep 2008, at 23.48, James G. wrote:
require ‘open-uri’
painfully slow if you need to make a bunch of uuid’s.My favorite trick is:
uuid =
uuidgen
.stripIt has always been fast enough for my needs.
James Edward G. II
The variation I use is uuid = "x_#{`uuidgen`.strip}"
The advantage is that the generated uuid is always suitable as an xml ID
On Sep 1, 2008, at 14:48 , James G. wrote:
My favorite trick is:
uuid =
uuidgen
.stripIt 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
On Sep 1, 2008, at 4:27 PM, Ezra Z. wrote:
read.scan(/<h3>([-[:alnum:]]+)<\/h3>/).to_s
puts uuid
Regards,
Park H.
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 G. II
On Sep 1, 2008, at 5:38 PM, Ryan D. wrote:
almost all cases. thanks.
puts “# of iterations = #{max}”
end
endx.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.
Newb N. 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