Assignment #53 and Randomness
Code
/// Name: Graham Pollock
/// Period: 5
/// Program Name: Randomness
/// File Name: Randomness.java
/// Date Finished: 11/30/2015/
import java.util.Random;
public class Randomness
{
public static void main ( String[] args )
{
///when i changed the seed to 12353 it made the numbers the same very time
Random r = new Random();
///when i changed it to 300000 it produced a different set on the same numbers every time
int x = 1 + r.nextInt(10);
System.out.println( "My random number is " + x );
///taking away the 1 + makes it choose numbers from 0 to 5
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." );
}
}
}
Picture of the output