This is nearly a cross post from Math SE - while the explanation of my problem is identical, on Math.SE I was asking for a mathematical solution to my problem.
My issue is, the solution I got on Math.SE was "convert to base 35" which is probably a very good answer, but I am truly horrible with math and don't understand how to apply the solution in my code. I tried looking up a lesson on converting to different bases, and it's pretty confusing to me. Even looking at a question about converting numbers to bases in JavaScript didn't make it clear how exactly I'd use it for what I need to do.
Is there a simple way to handle this in JavaScript? Here's the question in full:
I have an unusual programming problem and the math side of it has me stumped.
I've generated a unique string of seven characters which are each randomly selected from these possibilities: ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789
for example A6HJ92B
and I need to convert it to a unique number value. When converted, no two versions of this random string can be the name number.
I could just generate a number rather than including letters in the original id, but of course that means I have to increase the length of my string, and it's possible that the user of my application may want to type this string, as it identifies his "session" in an application, so I want to keep it short.
So my idea was to build a table like this:
A : 1,
B : 2,
C : 3,
D : 4,
E : 5,
F : 6,
G : 7,
H : 8,
... you get the idea ...
5 : 31,
6 : 32,
7 : 33,
8 : 34,
9 : 35
And then I'd add all of the numbers up...
A6HJ92B
:
A : 1
6 : 32
H : 8
J : 10
9 : 35
2 : 28
B : 2
1+32+8+10+35+28+2 = 116
...but I realized this is a flawed idea because many possible strings will "collide" or equal the same number. I need each unique string to equal a unique number.
So even if I multiplied each character's value (1*32*8*10*35*28*2 = 5,017,600
), I'm thinking there might be possible collisions there too.
Is there a way to calculate this in a way that eliminates collisions? If the collisions cant be eliminated, what methods can I use to minimize them?