# Unique id custom creator - help

**URL:** <https://www.ruby-forum.com/t/unique-id-custom-creator-help/192305>\
**Category:** Rails\
**Created:** [July 28, 2010, 12:54am UTC](https://www.ruby-forum.com/t/unique-id-custom-creator-help/192305 "2010-07-28T00:54:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oliver\_torres](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a9a28c/32.png) [@oliver\_torres](https://www.ruby-forum.com/u/oliver_torres)\
**Post date:** [July 28, 2010, 12:54am UTC](https://www.ruby-forum.com/t/unique-id-custom-creator-help/192305/1 "2010-07-28T00:54:02Z")

</div>

I have a simple blog app that lets me create an entry with title and a  
body… real simple.  
In addition to the id that the database creates by default per each  
entry I would love to associate an unique id that uses  
0123456789 and the 26 letters of the English alphabet.

So that means I have 36^7 unique ids right? assuming I want to keep  
each unique combination no bigger than 7 digits, Why? This is  
hypothetical.  
Can anyone help point me into the right direction?  
the intended result would be 00001, 00002, 00003 etc etc.

I was thinking to using a foor loop but a friend said that was a bad  
idea.  
A newbie here, I guess i dont have to point that out, anyone that can  
help me will be great.  
Thanks  
Oliver.

---

<div class="post-metadata">

**Author:** ![oliver\_torres](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a9a28c/32.png) [@oliver\_torres](https://www.ruby-forum.com/u/oliver_torres)\
**Post date:** [July 28, 2010, 3:56pm UTC](https://www.ruby-forum.com/t/unique-id-custom-creator-help/192305/2 "2010-07-28T15:56:07Z")

</div>

Quoting oliver torres [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> the intended result would be 00001, 00002, 00003 etc etc.
> 
> I was thinking to using a foor loop but a friend said that was a bad  
> idea.  
> A newbie here, I guess i dont have to point that out, anyone that can  
> help me will be great.  
> Thanks

irb(main):006:0\> 50.to\_s(36)  
=\> “1e”

50 base 36 = 1\*36 + 14

HTH,  
Jeffrey

---

<div class="post-metadata">

**Author:** ![oliver\_torres](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a9a28c/32.png) [@oliver\_torres](https://www.ruby-forum.com/u/oliver_torres)\
**Post date:** [July 28, 2010, 8:06pm UTC](https://www.ruby-forum.com/t/unique-id-custom-creator-help/192305/3 "2010-07-28T20:06:08Z")

</div>

Jeffrey L. Taylor wrote:

> Quoting oliver torres [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > the intended result would be 00001, 00002, 00003 etc etc.
> > 
> > I was thinking to using a foor loop but a friend said that was a bad  
> > idea.  
> > A newbie here, I guess i dont have to point that out, anyone that can  
> > help me will be great.  
> > Thanks
> 
> irb(main):006:0\> 50.to\_s(36)  
> =\> “1e”

That works really well. If you’d like something more sophisticated, you  
could implement Doug Crockford’s base-32 algorithm described at  
[Base 32](http://crockford.com/wrmg/base32.html) . I’ve got some code for that  
algorithm at  
[http://groups.google.com/group/techvalleyrb/msg/ac3ce4ae6620268a](http://groups.google.com/group/techvalleyrb/msg/ac3ce4ae6620268a) that I  
probably should put into a gem…

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
