Results 1 to 4 of 4

Thread: Program for random method

  1. #1
    Join Date
    Nov 2009
    Posts
    1,035

    Program for random method

    Hi all,

    I am Bsc(IT) student with too much confusion. I need a program which will demonstrate me the how to use Random() method in the program. I have some programming books, but no one contains any proper example of the random() method.
    If you have any example which explain the use of the random method(), then please provide me that. Example in any programming language will work for me.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Program for random method

    Hi, Below is the simple Java program code which shows the use of the random() method within program:
    class GetRandomNum{

    public static void main(String[] arg)
    {

    double rndNum = Math.random();

    System.out.print("Random number =", +rndNum);

    }

    }

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Program for random method

    I have the java code which prints the random number of any data type such as boolean type, float type , integer type, long type etc :
    import java.util.Random;

    class RandomNumDemo{

    public static void main(String[] arg){


    Random RandomDemo = new Random();


    System.out.println(RandomDemo.nextFloat());


    System.out.println(RandomDemo.nextInt());


    System.out.println(RandomDemo.nextLong());


    System.out.println(RandomDemo.nextBoolean());

    System.out.println(RandomDemo.nextInt(10) + 1);


    System.out.println(RandomDemo.nextDouble());



    }

    }

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Program for random method

    Following program displays the random number in range of the 1500. Please copy following program and execute it:
    import java.util.Random;

    class GnrtRandNumbers{

    public static void main(String[] args){


    Random num = new Random(); //define a new instance of the Random class



    num.Set(1500);


    System.out.print(num.nextInt()); //print a random number

    }
    }

Similar Threads

  1. Problem in using random method in java
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 13-02-2010, 02:22 AM
  2. C sharp program to print random numbers
    By Prashobh Mallu in forum Software Development
    Replies: 5
    Last Post: 12-01-2010, 12:07 PM
  3. Replies: 3
    Last Post: 22-12-2009, 09:11 PM
  4. Procedure to run Java program without main method
    By Sheena_thakkar in forum Software Development
    Replies: 3
    Last Post: 26-11-2009, 02:57 PM
  5. What is method overriding and method overloading in java
    By beelow in forum Software Development
    Replies: 3
    Last Post: 17-11-2009, 08:20 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,024,311.52269 seconds with 16 queries