Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Need help understanding math.random method.

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help understanding math.random method.

    I'm trying to make an applet show 3 random images with 1 image containing text each time it is closed or restarted.

    What confuses me even more is that I have to make a random flag after the start() method to determine which image should be shown.

    here is the project to help clarify:

    In your applet, randomly show an image when the applet is started or restarted. Also, print a message on the applet, depending on which image is shown. Hints: the start() method would be a good place to put some sort of random flag to determine which image should be shown. It is also a good place to call a separate method to set the image and message. The paint() method should only do the actual drawing of the image and the message. Separate methods can be created to set the image and the message into variables for the paint() method to use.


  2. #2
    Member
    Join Date
    Feb 2012
    Posts
    106
    My Mood
    Yeehaw
    Thanks
    8
    Thanked 11 Times in 11 Posts

    Default Re: Need help understanding math.random method.

    Math is a Class offered by the Java library. It has the method Random().
    With out explaining too much about how it works, it might be easier for you to look up in Google: "Java dice roller"
    This will give you code to select a number 1, 2, or 3 randomly, which I think will suit your purposes.

    Goodluck,
    Jonathan

Similar Threads

  1. display the generated Math.random number
    By PsYNus in forum What's Wrong With My Code?
    Replies: 11
    Last Post: November 2nd, 2011, 10:25 AM
  2. Math.Random()
    By xionyus in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 26th, 2011, 10:22 PM
  3. Creating a new class and dont know how to generate a random number math code
    By beatlebaby70 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 15th, 2011, 03:03 PM
  4. random not working in .class method
    By Spidey1980 in forum Java SE APIs
    Replies: 13
    Last Post: August 19th, 2011, 07:35 AM
  5. Need help understanding method calls and such
    By hackman2007 in forum Java Theory & Questions
    Replies: 8
    Last Post: July 14th, 2010, 08:18 AM