package java.util provides Random Class. Random Class has method nextInt(n). This method will return any number between 0 - n(int value). This method will successfully return integer value only on devices having configuration greater than CLDC 1.0.

Below is an example of Random class that return any number between 0-10.

 import javax.microedition.midlet.*;
import java.util.*;

public class testRandom extends MIDlet 
{
  public static void testRandom() 
  {
  }

  public void startApp()
  {
    Random r = new Random();
    int i = r.nextInt(10);
    System.out.println( i);
  }

  public void pauseApp()
  {}

  public void destroyApp(boolean destroy) {}
}

 

For devices with CLDC 1.0 below is the method to implement above functionality.

 public void startApp()
{
  Random r = new Random();
  int i = r.nextInt() % <10>;
  System.out.println( i);
}