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
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 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
    
    4
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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: how to get a random alphabet or char ?
 
Similar Threads
help with creating random strings in an array
WA #1.....word association
String to char problems
NumberFormatException
Input