SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
UniformIntGen.java
1/*
2 * Class: UniformIntGen
3 * Description: random variate generator for the uniform distribution over integers
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.randvar;
26
27import umontreal.ssj.rng.*;
28import umontreal.ssj.probdist.*;
29
43public class UniformIntGen extends RandomVariateGenInt {
44 protected int left; // the left limit of the interval
45 protected int right; // the right limit of the interval
46
51 public UniformIntGen(RandomStream s, int i, int j) {
52 super(s, new UniformIntDist(i, j));
53 setParams(i, j);
54 }
55
60 super(s, dist);
61 if (dist != null)
62 setParams(dist.getI(), dist.getJ());
63 }
64
70 public static int nextInt(RandomStream s, int i, int j) {
71 return UniformIntDist.inverseF(i, j, s.nextDouble());
72 }
73
77 public int getI() {
78 return left;
79 }
80
84 public int getJ() {
85 return right;
86 }
87
88 protected void setParams(int i, int j) {
89 if (j < i)
90 throw new IllegalArgumentException("j < i");
91 left = i;
92 right = j;
93 }
94}
Extends the class DiscreteDistributionInt for the discrete uniform distribution over the range .
static int inverseF(int i, int j, double u)
Computes the inverse of the discrete uniform distribution function ( invuniformint ).
int getJ()
Returns the parameter .
static int nextInt(RandomStream s, int i, int j)
Generates a new uniform random variate over the interval.
UniformIntGen(RandomStream s, int i, int j)
Creates a uniform random variate generator over the integers in the closed interval ,...
UniformIntGen(RandomStream s, UniformIntDist dist)
Creates a new generator for the distribution dist, using stream s.
int getI()
Returns the parameter .
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...
double nextDouble()
Returns a (pseudo)random number from the uniform distribution over the interval , using this stream,...