File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Randomize a set of words Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Randomize a set of words" Watch "Randomize a set of words" New topic

Randomize a set of words

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Hi. Not sure if this is the right place to post this. We are trying to create a table that has a ton of four letter words in it(minus the nasty ones ). Right now we have the list of words in an Excel spreadsheet in alphabetical order. We want to scramble these so when we use them to be assigned as order codes, they don't get assigned alphabetically. My question is, how do I do this? Can anyone supply me with some java code to get this done, or at least give me a couple of hints where to look?
Thanks in advance!!
Michael Matola
Ranch Hand

Joined: Mar 25, 2001
Posts: 1790
Take a look at Collections.shuffle() to see it can help you out.
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
You can try something like this

This will return the String[] in a completely random order.
[ April 08, 2002: Message edited by: Carl Trusiak ]

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Thanks guys!!
I agree. Here's the link:
subject: Randomize a set of words
It's not a secret anymore!