This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How do i create random strings? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "How do i create random strings?" Watch "How do i create random strings?" New topic
Author

How do i create random strings?

Andrew Stevens
Greenhorn

Joined: May 29, 2001
Posts: 3
I need a no paramater constructor that generates a random 4 letter string. Is there a way to do this using Math.random?
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4118
    
    2

char randomLetter = (char)('A' + (Math.random() * 26));
I'm leaving the rest for you to figure out just in case this is a school assignment
Junilu

Junilu - [How to Ask Questions] [How to Answer Questions] [MiH]
Siobhan Murphy
Ranch Hand

Joined: Oct 19, 2000
Posts: 72
You could create a collection of the 26 characters, shuffle the Collection and select four elements.
Best wishes
 
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 do i create random strings?
 
Similar Threads
Random Number Chooser programming exercise
Please Help
Simple Question
Help with random class
WA #1.....word association