Unique in what context?
Originally posted by John Todd:
Hi.
I want to create an algorithm that create a unique 8-length charaters String, like :
ADIGJEZC, ERLOCBDO .....
Any ideas ?
Thanks for help.
There are hints in the question that you want the string you get from this algorithm to be different from some other set of strings. There are also hints that a database is involved. But the question "Unique in what context?" still hasn't been answered.Originally posted by John Todd:
When ever I run the algorithm, I have to get a new String.
(Assume this algorithm is used to create PKs).
There's also a tendency for people to ask the second question. I.e.Originally posted by Rick O'Shay:
I noticed folks at The Ranch often fail to distill the germ of their question and leave out critical details.
jherald
Originally posted by Jherald Lacambra:
here's a javascript that i have created that generates 8 characters string. Just convert the methods into java...
}
Originally posted by Rick O'Shay:
Remember that characters are people too, er... numbers.
jherald
Originally posted by Rick O'Shay:
[QB]
BTW, what makes you think you could not filter out E, f, d in a loop? A minor tweak to the loop is all that is required. KISS!!! Keep It Simple Students!
for me its still simplier just to remove n(number of)characters to be randomize that having to modify codes? do you think so? how about removing 5 characters, ill just remove them from array the code is still intact, if i add 10 characters do i have to modify the codes? ill just modify the array..
Yes, you can change the letters but for what purpose? Let's leave aside efficiency and bloat issues and ask what the actual task is and what's the simplest way that we can achieve that in a reasonably extensible way.
The idea is to generate a string of N random characters withing a range R. That little loop will do that. There is nothing sequential about the result. It's essentially random. What purpose would it serve to choose your own non sequential characters if you are going to pick them randomly?
may randomizing the letters will not be an answer coz the will be 208827064576 possible combinations of letters will be formed.. if we will randomly create the string, the string might not be unique although there are alot of combinations.. maybe its better to do it sequentially based the number of characters
letters say A is 0,B is 1,C is 2,....
if you will make A as 0 then the first string will be 'AAAAAAAA' or 0000000000000000 the if you increment the last 0 by 1 it would be 0000000000000001 or 'AAAAAAAB' then strings will be unique to each other. until you reach 2626262626262626 or 'ZZZZZZZZ'
jherald