random number generator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cwalster
    New Member
    • Sep 2007
    • 1

    #1

    random number generator

    im in a java class and need to make a program that displays 6 random numbers between 1 and 49. ive gotten the display part to work... but the random generator confounds my logic. help PLEASE
  • stack
    New Member
    • Sep 2007
    • 40

    #2
    One way to do this is by using the Random class within the java util package. The nextInt(int n) method will solve your problem (Returns an int value between 0 and the specified value(n) minus 1!). Of course you will need a loop too since you need 6 numbers.
    Good luck :-)

    Comment

    • saharf
      New Member
      • Sep 2007
      • 4

      #3
      Originally posted by cwalster
      im in a java class and need to make a program that displays 6 random numbers between 1 and 49. ive gotten the display part to work... but the random generator confounds my logic. help PLEASE
      you can use nextInt(int) method of the java.util.Rando m class, found in java documentation. also u can find an example overthere.

      Comment

      • MarkoKlacar
        Recognized Expert Contributor
        • Aug 2007
        • 296

        #4
        Hi,

        just a word of advice, the nextInt(Number) begins at '0', so if you want to generate a number between 1-49 don't forget to add the '+1' after nextInt(Number) .

        If you already didn't figure that one out.

        Comment

        Working...