File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get a random alphabet or char ?

 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Sunny Bhandari
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not directly...

Consider using String.charAt(int index) method and supply the index by generating random number.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
Campbell Ritchie
Sheriff
Pie
Posts: 47228
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunny Bhandari wrote: . . . Consider using String.charAt(int index) method . . .
I don't think that was what the original poster meant.
 
Rob Spoor
Sheriff
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know, you can do this exactly like that:
 
Sunny Bhandari
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya Rob that was what I had suggested.

Thanks for putting it in working code
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic