Random.java


/*Random.java

< applet
code=Random
width=225
height=200 >
< /applet >

This applet demonstrates various ways to output random numbers.*/

import java.util.Random;//No required for Math.random
import java.applet.*;
import java.awt.*;

public class Random extends Applet
{
	
    //double 1.7e-308 to 1.7e+308
    //float 3.4e-038 to 3.4e+038
	
	
    /* Sets the seed value (that is, the starting point for
       the random number generator) to that specified by newSeed
       void setSeed(long newSeed);*/
	
       Random r= new Random();//Not required for Math.random
       double r1= r.nextDouble();//Returns the next double random #
       float r2= r.nextFloat();//Returns the next float number.

      /*Next Gaussian gets 100 random Gaussian values and averages
	them.  The program also counts the number of values that fall within
	two standard deviations, +-, using increments of ).5 for each
	category.*/
        double r3= r.nextGaussian();
	
        int r4= r.nextInt();//Returns the next int random number.
        long r5=r.nextLong();//Returns the next long random number.

      /*Below is an alternative way to output a random number
	between zero and ten exclusively using the Math class.*/
        int r6 = (int) (Math.random() * 11); 

        Label Line1= new Label("double random = "+r1+"");
        Label Line2= new Label("float random = "+r2+"");
        Label Line3= new Label("Gaussian random = "+r3+"");
        Label Line4= new Label("int random = "+r4+"");
        Label Line5= new Label("long random = "+r5+"");
        Label Line6= new Label("Math Class random = "+r6+"");
	
	
	
	public void init()
	{
           add(Line1);
           add(Line2);
           add(Line3);
           add(Line4);
           add(Line5);
           add(Line6);
	}	
	

}

Output for Random.java