| Author |
how to get a random alphabet or char ?
|
Rahul Sudip Bose
Ranch Hand
Joined: Jan 21, 2011
Posts: 637
|
|
I want to get a random alphabet or char (and save it as a string, if possible)? Is there anything like Math.random() to do this ?
PS : Any ideas for a beginner level algorithm to make your own random generator which can generate strings,chars etc ? Is this advanced level stuff ?
|
SCJP 6. Learning more now.
|
 |
Sunny Bhandari
Ranch Hand
Joined: Dec 06, 2010
Posts: 446
|
|
Not directly...
Consider using String.charAt(int index) method and supply the index by generating random number.
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
Have you tried to search for it? Because when I type "java math.random" in google, the first hit is the class Math with the method random().
I'll give you a hint: a char is a number. So if you can generate a random number....
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
Sunny Bhandari wrote: . . . Consider using String.charAt(int index) method . . .
I don't think that was what the original poster meant.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
I don't know, you can do this exactly like that:
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Sunny Bhandari
Ranch Hand
Joined: Dec 06, 2010
Posts: 446
|
|
ya Rob that was what I had suggested.
Thanks for putting it in working code
|
 |
 |
|
|
subject: how to get a random alphabet or char ?
|
|
|