Assignment #53
Code
///Name: Cody Swain
///Period: 6
///Project Name: Randomness
///File Name: Randomness.java
///Date: 11/12/15
import java.util.Random;
public class Randomness
{
public static void main ( String[] args )
{
Random r = new Random();
int x = 1 + r.nextInt(10);
System.out.println( "My random number is " + x );
System.out.println( "Here are some numbers from 1 to 5!" );
System.out.print( 3 + r.nextInt(5) + " " );
System.out.print( 3 + r.nextInt(5) + " " );
System.out.print( 3 + r.nextInt(5) + " " );
System.out.print( 3 + r.nextInt(5) + " " );
System.out.print( 3 + r.nextInt(5) + " " );
System.out.print( 3 + r.nextInt(5) + " " );
System.out.println();
System.out.println( "Here are some numbers from 1 to 100!" );
System.out.print( 1 + r.nextInt(100) + "\t" );
System.out.print( 1 + r.nextInt(100) + "\t" );
System.out.print( 1 + r.nextInt(100) + "\t" );
System.out.print( 1 + r.nextInt(100) + "\t" );
System.out.print( 1 + r.nextInt(100) + "\t" );
System.out.print( 1 + r.nextInt(100) + "\t" );
System.out.println();
int num1 = 1 + r.nextInt(10);
int num2 = 1 + r.nextInt(10);
if ( num1 == num2 )
{
System.out.println( "The random numbers were the same! Weird." );
}
if ( num1 != num2 )
{
System.out.println( "The random numbers were different! Not too surprising, actually." );
}
}
}
/*
1. New Range is 0-4 including o and 4
2. New Range when adding +3 infront of r.nextInt(5) makes the range 3 - 7 including 7
3. When changing the random number seed, the numbers generated are no longer randomized. They are the same.
4. Changing the seed to 1 made all the random numbers generated very similar. I.E, they all had a 1 in them
*/
Picture of the output