From: Raphael Clancy Date: 2009-02-15T01:06:03+09:00 Subject: Re: uniuq no Vetrivel Vetrivel wrote: > I want to create new unique id in ruby.I have used the following > coding.But I don''t know whether it works perfectly or not. > > t = Time.new > p "%10.5f" % t.to_f > > does it give unique value always.I you know some other way ,please say > to create unique id . How about something like this... count = 0 t = Time.now.to_s 10000.times { if( t == Time.now.to_s) count = count + 1 else count = 0 t = Time.now.to_s end uniqid = t + "." + count.to_s puts uniqid } That way you don't have to worry about rounding, or the possibility that the same random number might come up twice. The only real problem with this scheme is that on a very fast computer it might be possible to generate more ids each second than will fit in an Int. But, Bignum might be able to help there... -- Posted via http://www.ruby-forum.com/.