Unique data

Hi,

I’d like to use the gem “rubytree” to store some data in a tree.
But this requires a unique name for each node.

Does anybody has some advice, how to generate such a unique id?
Could be a random, but unique number, …

Thanks
Peter

Peter M. wrote:

Does anybody has some advice, how to generate such a unique id?
Could be a random, but unique number, …

Hi Peter,

How about a type-4 UUID?

class UUID
@@range = %{0123456789abcdef}.split(//)
@@indices = [7,11,15,19]
def self.new
uuid=[]
32.times { |i|
uuid << @@range[rand(16)]
uuid << ‘-’ if @@indices.include?(i)
}
uuid.join
end
end
puts UUID.new

Mabye just using the object_id of the node itself or the object you’re
inserting into the node would work?

Regards,
Jordan

Peter M. wrote:

Hi,

I’d like to use the gem “rubytree” to store some data in a tree.
But this requires a unique name for each node.

Does anybody has some advice, how to generate such a unique id?
Could be a random, but unique number, …

Why not use a counter?

robert

Robert K. wrote:

Why not use a counter?

Doh! Curse you rubyists for always thinking of easy ways to do things!
I’m going to fire up perl5 and write some code, just to spite you! :wink:

Regards,
Jordan