Results 1 to 3 of 3
  1. #1
    gradon is offline Member
    Join Date
    Jul 2007
    Posts
    4
    Rep Power
    0

    Default getting a random result

    so i want to make a button and when you click it you see a random joke every time, now i know how to shuffle a array but how on earth can you make it that only 1 string gets randomly picked from a list of strings and how do you print it
    thanks

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    Lets assume that you put your string inside str array. You will implement random selection like this:

    Java Code:
    Random rand = new Random();
    rand.nextInt(str.length);
    Check javadoc of Random class for details.

  3. #3
    gradon is offline Member
    Join Date
    Jul 2007
    Posts
    4
    Rep Power
    0

Similar Threads

  1. random numbers without random class`
    By carlos123 in forum New To Java
    Replies: 4
    Last Post: 01-17-2008, 11:44 PM
  2. Iterating through result set in JSTL
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-15-2008, 04:13 PM
  3. Iterating through result set in JSTL
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-14-2008, 10:31 AM
  4. Replies: 1
    Last Post: 08-07-2007, 06:04 AM
  5. Blank result for jsp_servlet in Eclipse
    By Unni in forum Eclipse
    Replies: 2
    Last Post: 07-12-2007, 05:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •