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

net.finmath.randomnumbers.MersenneTwister Maven / Gradle / Ivy

Go to download

finmath lib is a Mathematical Finance Library in Java. It provides algorithms and methodologies related to mathematical finance.

There is a newer version: 6.0.19
Show newest version
/*
 * (c) Copyright Christian P. Fries, Germany. Contact: [email protected].
 *
 * Created on 17.06.2016
 */

package net.finmath.randomnumbers;

import java.io.Serializable;

/**
 * Mersenne Twister random number generator. This class is just a wrapper of
 * org.apache.commons.math3.random.MersenneTwister.
 *
 * @author Christian Fries
 *
 * @version 1.0
 */
public class MersenneTwister implements RandomNumberGenerator1D, Serializable {

	private static final long serialVersionUID = -1827470318370174186L;

	private final org.apache.commons.math3.random.MersenneTwister mersenneTwister;

	public MersenneTwister(final long seed) {
		mersenneTwister	= new org.apache.commons.math3.random.MersenneTwister(seed);
	}

	public MersenneTwister() {
		mersenneTwister	= new org.apache.commons.math3.random.MersenneTwister();
	}

	/**
	 * Returns the next random number in the sequence.
	 *
	 * @return The next random number in the sequence.
	 */
	@Override
	public double nextDouble() {
		synchronized (mersenneTwister) {
			return mersenneTwister.nextDouble();
		}
	}

	@Override
	public double nextDoubleFast() {
		return mersenneTwister.nextDouble();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy