All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aima.core.util.MockRandomizer Maven / Gradle / Ivy

Go to download

AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.

The newest version!
package aima.core.util;

/**
 * Mock implementation of the Randomizer interface so that the set of Random
 * numbers returned are in fact predefined.
 * 
 * @author Ravi Mohan
 * 
 */
public class MockRandomizer implements Randomizer {

	private double[] values;
	private int index;

	/**
	 * 
	 * @param values
	 *            the set of predetermined random values to loop over.
	 */
	public MockRandomizer(double[] values) {
		this.values = new double[values.length];
		System.arraycopy(values, 0, this.values, 0, values.length);
		this.index = 0;
	}

	//
	// START-Randomizer
	@Override
	public double nextDouble() {
		if (index == values.length) {
			index = 0;
		}

		return values[index++];
	}
	// END-Randomizer
	//
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy