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

I need a code that can generate random numbers!!?

Discussion in 'Java' started by pakman, May 3, 2010.

  1. pakman

    pakman New Member

    Joined:
    May 3, 2010
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    I need someones help in finding or creating a code that can generate random numbers in JAVA.
    it can be from using API or any other sources that are out there. I also need an explanation on how the code works!! PLEASE HELP ME!!!
    Thank You
    Additional Details

    The thing is i dont know how to create a random generator code either.. and i dont really have the time to learn this in one night because its due in the morning.
    Please i need your help!
     
  2. LynxSI

    LynxSI New Member

    Joined:
    May 23, 2010
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Developer
    Location:
    Vancouver, BC, Canada
    Home Page:
    This capability is built into the java.util library! Just import the library using:
    Code:
    import java.util.*;
    Now you can create an instance of the Random class wherever you need it. Once you have your instance you can use one of several methods to generate a random number:
    Code:
    Random generator = new Random();
    int randomIndex = generator.nextInt( nMaxReturnVal );
    For more information just google "java random number generator" and you'll get many articles on the subject.

    - Ben
     

Share This Page