1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Beginner in java, need to write a random number generator.

Discussion in 'Java' started by ChristopherThe Great, Mar 13, 2009.

  1. ChristopherThe Great

    ChristopherThe Great New Member

    Joined:
    Mar 13, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello everyone, I am new to java and am having quite a bit of trouble with it. I have to write a random number generator with numbers between 0-50. I also have to put something in with a determineLowest to return the lowest number. I am using Eclpise to write and test the program. Can anyone offer me some pointers or places to start? I have browsed through my book, and it did not help me at all. Thanks.
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Did you try Googling "java random numbers"?
     
  3. Ascendancy

    Ascendancy New Member

    Joined:
    Feb 20, 2007
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    One of the first results from Google. Enjoy:

    Code:
    import java.util.Random;
    
    /** Generate 10 random integers in the range 0..99. */
    public final class RandomInteger {
      
      public static final void main(String... aArgs){
        log("Generating 10 random integers in range 0..99.");
        
        //note a single Random object is reused here
        Random randomGenerator = new Random();
        for (int idx = 1; idx <= 10; ++idx){
          int randomInt = randomGenerator.nextInt(100);
          log("Generated : " + randomInt);
        }
        
        log("Done.");
      }
      
      private static void log(String aMessage){
        System.out.println(aMessage);
      }
    }
    
     

Share This Page