## JAVA EXAMPLE PROGRAMS

Publish Your Article Here

# Program: Basic random number generator.

 Description: Many times we need to generate sequence of numbers. It is not a problem to generate sequence of numbers. But some times we need to generate random numbers. In java we can generate random numbers by using Random class. By using Random class, we can generate random integers, long numbers and double values. Below example shows how to generate random numbers using Random class.

 Code: ```package com.java2novice.random; import java.util.Random; public class MyBasicRandom { public static void main(String a[]){ Random rand = new Random(); System.out.println("Random Integers:"); System.out.println(rand.nextInt()); System.out.println(rand.nextInt()); System.out.println(rand.nextInt()); System.out.println("Random Double Numbers:"); System.out.println(rand.nextDouble()); System.out.println(rand.nextDouble()); System.out.println(rand.nextDouble()); System.out.println("Random Long Numbers:"); System.out.println(rand.nextLong()); System.out.println(rand.nextLong()); System.out.println(rand.nextLong()); } } ```

 Output: ```Random Integers: 1400247241 953993278 830962592 Random Double Numbers: 0.19841760470907022 0.32964328277263866 0.4624594748136943 Random Long Numbers: 4925512194471935414 2115815340178756456 4896741386551752249 ```

#### List of Random class sample programs:

Java2Novice - YouTube Channel
Knowledge Centre
ServletOuptputStream Vs PrintWriter
ServletOutputStream: ServletResponse.getOutputStream() returns a ServletOutputStream suitable for writing binary data in the response. The servlet container does not encode the binary data, it sends the raw data as it is.

PrintWriter: ServletResponse.getWriter() returns PrintWriter object which sends character text to the client. The PrintWriter uses the character encoding returned by getCharacterEncoding(). If the response's character encoding has not been specified then it does default character encoding.
Famous Quotations
Good judgment comes from experience, and experience comes from bad judgment.
-- Barry LePatner

### Other Interesting Sites

 Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle. Privacy Policy | Copyright © 2024 by Nataraja Gootooru. All Rights Reserved.