SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
RandomVariateGenInt.java
1/*
2 * Class: RandomVariateGenInt
3 * Description: base class for all generators of discrete random variates
4over the integers
5 * Environment: Java
6 * Software: SSJ
7 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
8 * Organization: DIRO, Universite de Montreal
9 * @author
10 * @since
11 *
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *
25 */
26package umontreal.ssj.randvar;
27
28import umontreal.ssj.rng.RandomStream;
29import umontreal.ssj.probdist.DiscreteDistributionInt;
30
41public class RandomVariateGenInt extends RandomVariateGen {
42
43 protected RandomVariateGenInt() {
44 }
45
54 this.stream = s;
55 this.dist = dist;
56 }
57
66 public int nextInt() {
67 return ((DiscreteDistributionInt) dist).inverseFInt(stream.nextDouble());
68 }
69
80 public void nextArrayOfInt(int[] v, int start, int n) {
81 if (n < 0)
82 throw new IllegalArgumentException("n must be positive.");
83 for (int i = 0; i < n; i++)
84 v[start + i] = nextInt();
85 }
86
96 public int[] nextArrayOfInt(int n) {
97 if (n <= 0)
98 throw new IllegalArgumentException("n must be positive.");
99 int[] v = new int[n];
100 for (int i = 0; i < n; i++)
101 v[i] = nextInt();
102 return v;
103 }
104
114
115}
Classes implementing discrete distributions over the integers should inherit from this class.
void nextArrayOfInt(int[] v, int start, int n)
Generates n random numbers from the discrete distribution contained in this object.
DiscreteDistributionInt getDistribution()
Returns the umontreal.ssj.probdist.DiscreteDistributionInt used by this generator.
int nextInt()
Generates a random number (an integer) from the discrete distribution contained in this object.
int[] nextArrayOfInt(int n)
Generates n random numbers from the discrete distribution contained in this object,...
RandomVariateGenInt(RandomStream s, DiscreteDistributionInt dist)
Creates a new random variate generator for the discrete distribution dist, using stream s.
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...