Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Beginner in java, need to write a random number generator. (http://www.go4expert.com/forums/beginner-java-write-random-generator-t16534/)

ChristopherThe Great 13Mar2009 20:51

Beginner in java, need to write a random number generator.
 
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.

xpi0t0s 19Mar2009 06:10

Re: Beginner in java, need to write a random number generator.
 
Did you try Googling "java random numbers"?

Ascendancy 19Mar2009 18:37

Re: Beginner in java, need to write a random number generator.
 
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);
  }
}



All times are GMT +5.5. The time now is 20:46.