Generate Unique ID

June 23, 2008

Here is a very simple way to generate a unique id.
[Background support : Abhishek S.]

def generate_unique_id( len )
    chars_pattern = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
    unique_id = ""
    1.upto(len) {
			|i| unique_id << chars_pattern[rand(chars_pattern.size-1)]  }
    return unique_id
end
#generates a key of length 10
mykey = generate_unique_id(10)
print mykey # gives a result like "qeKX0myIQh"

Entry Filed under: RoR, coding. Tags: , , , , , , , .

Leave a Comment

hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Categories

posts[:recent]

episodes[:recycled]

@@name = PRAYAS

Step down at my blog with your ideas,comments,suggestions on Ruby,RoR,Ajax or Web2.0.You may reach me at
infostall@gmail.com

find_by_tags

1st April 37signals 360 2008 aamir aamir new look abdul abhinay access active active record aishwarya AJAX AMC amul and bollywood class facebook ghajini google hosting India instance local mozilla myspace nil NY object objects olympic plugin prayas programming Rails RoR Ruby security talent variables web web2.0 windows yahoo

Blogroll

visitors[:since_Mar'08]

free web counter

Spam Blocked

Feeds

Meta

RSS Prayas here