Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Get Random Number 
 

Random Number is the set of unordered arranged number. The class Random is derived from java.util.Random.An instance of Random class is used to provide you a stream of pseudorandom number.

 

Get Random Number

                         

Random Number is the set of unordered arranged number. The class  Random is derived from java.util.Random.An instance of Random  class is used to provide you a stream of pseudorandom number.

In this Tutorial we want to describe you a code that helps you in understanding  to Get Random Number. For this we have a class name Get Random Number. Inside the main method we create an instance of random class using new operator. The for loop is used to print the number and work as iterartor by using System.out.println.

1)Random.nextInt( )-The Method returns you the set of pseudorandom number executed till 10 times as specified in the for loop.

2)Random nextInt(int )-The Method returns you the pseudorandom, uniformly distributed int value one less than the specified int value.

On Execution the code show you a set of Random number in the command prompt from 0-9 in any sequence.

GetRendomNumber.java

import java.util.Random;

public class GetRendomNumber {

    public static void main(String args[]) {

        Random random = new Random();
        for (int i = 0; i < 10; i++) {
            System.out.println("Random number : " + random.nextInt(10));
        }
    }
}

Output
Random number : 5
Random number : 2
Random number : 6
Random number : 0
Random number : 5
Random number : 2
Random number : 7
Random number : 1
Random number : 2
Random number : 0
 

Download code

                         

» View all related tutorials
Related Tags: java c mac process io virtual vi number this sso ai processor to proc e il section machine ce in

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.