Results 1 to 5 of 5

Thread: random number generation

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Posts
    163

    random number generation

    How to generate random number in java?
    Purushottam

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Math.random()

    Will generate a random number between 0 and 1.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    Or you can instantiate an object of Random
    import java.util.Random;

    Random x = new Random();
    x.nextInt(5); returns an int value [0,5)

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Posts
    163
    but it gives error

    impot java.util.Ramdom

    class a
    {
    public static void main()
    {
    Random i=new Random();
    }

    }
    Purushottam

  5. #5
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    impot???
    Ramdom???

    I'm guessing you just typed that in the thread, so post the error you get. If you didn't, check your spelling

    Also thought you needed String[] args as input in the main procedure.

Posting Permissions

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



Click Here to Expand Forum to Full Width