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

umontreal.iro.lecuyer.randvar.UniformGen Maven / Gradle / Ivy

Go to download

SSJ is a Java library for stochastic simulation, developed under the direction of Pierre L'Ecuyer, in the Département d'Informatique et de Recherche Opérationnelle (DIRO), at the Université de Montréal. It provides facilities for generating uniform and nonuniform random variates, computing different measures related to probability distributions, performing goodness-of-fit tests, applying quasi-Monte Carlo methods, collecting (elementary) statistics, and programming discrete-event simulations with both events and processes.

The newest version!


/*
 * Class:        UniformGen
 * Description:  random variate generators for the uniform distribution over the reals
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Université de Montréal
 * Organization: DIRO, Université de Montréal
 * @author       
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   GPL licence site.
 */

package umontreal.iro.lecuyer.randvar;
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.probdist.*;


/**
 * This class implements random variate generators for
 * the (continuous) uniform distribution over the interval (a, b),
 * where a and b are real numbers with a < b.
 * The density is 
 * 
 * 

*
* f (x) = 1/(b - a)         for a <= x <= b. *

* *

* The (non-static) nextDouble method simply calls inverseF on the * distribution. * */ public class UniformGen extends RandomVariateGen { private double a; private double b; /** * Creates a uniform random variate generator over the interval * (a, b), using stream s. * */ public UniformGen (RandomStream s, double a, double b) { super (s, new UniformDist(a, b)); setParams (a, b); } /** * Creates a uniform random variate generator over the interval * (0, 1), using stream s. * */ public UniformGen (RandomStream s) { this (s, 0.0, 1.0); } /** * Creates a new generator for the uniform distribution dist * and stream s. * */ public UniformGen (RandomStream s, UniformDist dist) { super (s, dist); if (dist != null) setParams (dist.getA(), dist.getB()); } /** * Generates a uniform random variate over the interval * (a, b) by inversion, using stream s. * */ static public double nextDouble (RandomStream s, double a, double b) { return UniformDist.inverseF (a, b, s.nextDouble()); } /** * Returns the value of a for this object. * */ public double getA() { return a; } /** * Returns the value of b for this object. * * */ public double getB() { return b; } /** * Sets the value of the parameters a and b for this object. * */ private void setParams (double a, double b) { if (b <= a) throw new IllegalArgumentException ("b <= a"); this.a = a; this.b = b; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy