
public class RandomNumbers {

	public static void main(String[] args) {
		//Math.random: randomly generate a number between 0 and 1 (not 1)
		System.out.println(Math.random());
		
		//a value between 0..10 (not 10)    [0,10)
		System.out.println(Math.random()*10);
		
		//now an int
		//first * 10, then cast
		System.out.println((int)(Math.random()*10));
		
		//flip a coin
		// heads: 0
		// tails: 1
		// 2 possible values
		int flip = (int)(Math.random()*2);
		System.out.print("You flipped: ");
		if(flip == 0) {
			System.out.println("Heads");
		}
		else {
			System.out.println("Tails");
		}
		
		//roll two 6-sided dice and print their sum
		int roll1 = (int)(Math.random()*6) + 1;
		int roll2 = (int)(Math.random()*6) + 1;
		System.out.println("The sum is " + (roll1 + roll2));
		
		
		//random int between -10 and 10 (inclusive)
		int number1 = (int)(Math.random()*21) - 10;
		int number2 = (int)(Math.random()*21) - 10;
		System.out.println(number1 + ", " + number2);
		
		//put them in order
		if(number1 > number2) {
			//they are out of order
			//swap the values
			int temp = number1;  //temporarily store the old value
			number1 = number2;
			number2 = temp;
		}
		System.out.println(number1 + ", " + number2);
		
		int value = (int)(Math.random()*21) - 10;
		
		//force value to be non-negative
		//(condition)? true-value : false-value
		value = (value < 0)? -value : value;
		
		System.out.println(value);
	}

}
