/*
 * RandomNumbers: a simple class to demonstrate Probekit.
 */
import java.util.Random;

/**
 * This class implements a random number simulation on the console.
 * First, the program selects a random number from one to ten.
 * If the random number is 10, the simulation ends with a "hit."
 * Otherwise the program selects random numbers until either
 *    (A) the new number matches the first number, or
 *    (B) the new number is 10.
 * In case (A) the simulation reports a "hit." In case (B) the
 * simulation reports a "miss."
 */
public class RandomNumbers {

	public static void main(String[] args) {
		RandomNumbers cd = new RandomNumbers();
		cd.runSimulation();
	}
	
	Random _randomSequence;
	
	public RandomNumbers() {
		_randomSequence = new Random();
	}

	/**
	 * Runs through a random number simulation, with output to stdout.
	 * @return true for a "hit," false for a "miss."
	 */
	public boolean runSimulation() {
		System.out.println("Random number simulation now starting.");
		int initialValue = getRandomNumber();
		if (initialValue == 10) {
			System.out.println("The initial random value is ten: hit.");
			return true;
		}
		else {
			System.out.println("The initial random value is not ten. Looking for a match.");
			while (true) {
				System.out.println("Target value is " + initialValue);
				int newValue = getRandomNumber(); 
				if (newValue == initialValue) {
					System.out.println("A match occurred before a ten: hit.");
					return true;
				}
				else if (newValue == 10) {
					System.out.println("Ten occurred before a match: miss.");
					return false;
				}
				else {
					System.out.println("No match, not a ten. Continuing.");
				}
			}
		}
	}
	
	int getRandomNumber() {
		int value = _randomSequence.nextInt(10) + 1;
		System.out.println("Next selected random value: " + value + ".");
		return value;
	}
}