Results 1 to 2 of 2
  1. #1
    fernando is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default How to generate random number in java

    Hi, How can i generate a random number from 10 to 99?

    Thanks

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Java Code:
    // Use the java.util.Random class
    Random rand = new Random();
    int n = 10 + rand.nextInt(90);
    // or, use the Math class method
    int m = (int)(10 + 90*Math.random());

Similar Threads

  1. Generate an event to another java application
    By i_berbeu in forum Advanced Java
    Replies: 18
    Last Post: 05-12-2008, 01:57 PM
  2. random numbers without random class`
    By carlos123 in forum New To Java
    Replies: 4
    Last Post: 01-17-2008, 10:44 PM
  3. Generate a random number
    By romina in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:23 AM
  4. How can I generate MsWord from java?
    By simon in forum Advanced Java
    Replies: 2
    Last Post: 08-01-2007, 04:40 PM
  5. Random Image on Refresh (FROM Folder not set number)
    By QuinnMal in forum Java Servlet
    Replies: 1
    Last Post: 07-06-2007, 07:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •