| Author |
how to generate random string...?
|
Damodara Reddy
Ranch Hand
Joined: Feb 09, 2007
Posts: 44
|
|
I need to generate a random key with 4 chars, for example anmk, lopu....etc.,. how can I do this..? Thanks in Advance Damodara Reddy
|
Damu
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
More a beginner's question. Chars are numbers, you do know that? So you can create a random number in the requisite range (for lower-case letters 0x61 to 0x7a inclusive) and cast it to a char. Then repeat three times.
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
|
You might want to omit vowels to avoid naughty words in however many langauges your users might know. You can make an array of acceptable letters, digits, punctuation, etc and pick them out randomly, or even use Arrays.shuffle() to mix them up and take the first four (which has the non-random property of no duplicates.)
|
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
|
 |
Srikanth Ramu
Ranch Hand
Joined: Feb 20, 2007
Posts: 76
|
|
|
If you want to generate random numbers its simple and follow as suggested in the above posts. However if you want to generate a key based on some input values then regenerate the input values based on the key, then you need to have a proper alogrithm to encode and decode keys.
|
 |
 |
|
|
subject: how to generate random string...?
|
|
|