# Generation of random number using random class

• April 16th, 2009, 06:10 AM
JavaPF
Generation of random number using random class
This code uses the Random class to generate a random number up to 100.

You can change the 100 value to any interger you wish.

Code Java:

```import java.util.*;   public class RandomNumber {   public static void main(String[] args) {   Random random = new Random(); int rand = random.nextInt(100);   System.out.println(rand);   }   }```
• December 7th, 2011, 04:46 PM
Emperor_Xyn
Re: How to Generate a random number using the Random class
PHP Code:

```  * To change this template, choose Tools | Templates  * and open the template in the editor.  */ package unogame; import java.util.*; import java.lang.*; import java.awt.*;          /**  *  * @author Xyn  */ public class UNOGame { static int ar;  int counter=0; static int winCount= 0; /**      * @param args the command line arguments      */     public static void main(String[] args) {      System.out.println("Welcome to Under or Over game.  Your opponnents number will be displayed and you have to go over or under it.");         for(int i=1; i<6; i++)  {      double cop = new Random() .nextInt(100) +1;      double plp = new Random() .nextInt(100) +1;       System.out.println(" The computers number is " + cop + " .")  ;            Scanner keyboard = new Scanner(System.in);      String pick = keyboard.next();       unofile uno = new unofile();                    if (pick.equals("over")) {          if (cop>plp) {               System.out.println("You win that round!");                           winCount++;           }}      if (pick.equals("under")) {          if (cop<plp) {               System.out.println("You lose that round!");                          }}      if (pick.equals("over")) {          if (cop<plp) {               System.out.println("You win that round!");                          winCount++;           }}      if (pick.equals("under")) {          if (cop>plp) {               System.out.println("You lose that round!");                            }}                    System.out.print("Your number was ");          System.out.print(plp + "." );                        }       unofile uno = new unofile();   uno.counterWin = winCount;  uno.writeWall();    }                          }  ```

Theres a sample of it in use. ((NOTE: POORLY CONSTRUCTED PROGRAM)