Subject: Re: Base 36
Date: Thu, 28 May 1998 16:25:49 -0400
From: Alex Bogomolny

Dear Peter:

> We have a need to generate a unique random number that can never be duplicated.

How often you plan to generate it? And for how long should it stay unique? In other words, how many unique numbers do you expect to generate?

> We are thinking of using a combination of date and time
> down to the millisecond level

Unless you do this more often then at most once a millisecond this should work subject to the above.

> Perhaps
> base 36 might help. All ideas appreciated.

You realize that numbers in base 36 look more like strings than numbers, right. If you want to store and manipulate your random number as a number, I am not sure how converting it to base 36 may help.

> Number could be: 9836623595999 (YRDDDHHMMSSss)

That's fine. An important question is, Are you going to use it only as ID or it may be used in math calculations? What is actually your concern? To have a unique ID whose storage takes as little space as possible? If this is not the case, there is no reason to use base 36.

You do not need a conversion calculator to estimate how long the result may be. However, take into account that a char in base 36 will take at least 6 bits. A digit in bases 10-16 takes only 4 bits. The most economical (bitwise) storage is to use any base which is a power of 2. It does not matter which. So I would use base 16 and pack two digits into a byte. You can't do better than that. (In base 32 you would have to pack eight 5-bit digits into 5 bytes - much less straightforward.)

See, if you need a math consultant. I would be happy to stop by. I am a faithful cardholder of the NationsBank.

Best regards,
Alexander Bogomolny

|Reply| |Up| |Exchange index| |Contents| |Store|

Copyright © 1996-2018 Alexander Bogomolny