GeeCON Prague 2014*
The moose likes Java in General and the fly likes Need an auto generation logic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Need an auto generation logic" Watch "Need an auto generation logic" New topic
Author

Need an auto generation logic

Neelima Mohan
Greenhorn

Joined: May 23, 2010
Posts: 27
Hi,

I need a random sequence generation logic. The sequence can be in the format
(2 alphabets with 1 digit) * n times
for eg :
RT2YU4JK7
PO6HJ2KA9RW3

Any pointers to help me in generating such a kind of sequence in java?

Thanks,
Neelima
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Is it always "letter letter digit", or can the digit also appear elsewhere? If it is the former then it's quite easy, considering that letters are chars and chars can be treated as ints. Math.random() or java.util.Random can then help:
The digit can be generated similarly except without the last step: Use a StringBuilder to add these all together, then at the end call toString().

Now, if the digit can appear anywhere then it's a bit harder but I'm sure you'll be able to work it out using my example code.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Neelima Mohan
Greenhorn

Joined: May 23, 2010
Posts: 27
thanks a bunch!
yes the sequence is specific to what I wrote...its only in <letter letter digit> form.
I will just work it out and see.
Your input has been very helpful

Thanks,
Neelima
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

You're welcome.
 
GeeCON Prague 2014
 
subject: Need an auto generation logic