aspose file tools*
The moose likes Beginning Java and the fly likes how to get a random alphabet or char ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to get a random alphabet or char ?" Watch "how to get a random alphabet or char ?" New topic
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: 448

Not directly...

Consider using String.charAt(int index) method and supply the index by generating random number.


Java Experience
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: 40029
    
  28
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: 19781
    
  20

I don't know, you can do this exactly like that:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sunny Bhandari
Ranch Hand

Joined: Dec 06, 2010
Posts: 448

ya Rob that was what I had suggested.

Thanks for putting it in working code
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get a random alphabet or char ?