SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
BakerTransformedStream.java
1/*
2 * Class: BakerTransformedStream
3 * Description: container class permits one to apply the baker's
4 transformation to the output of any RandomStream
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.rng;
27
44public class BakerTransformedStream implements RandomStream {
45
46 // The base stream.
47 private RandomStream st;
48
54 st = stream;
55 }
56
57 public void resetStartStream() {
58 st.resetStartStream();
59 }
60
61 public void resetStartSubstream() {
62 st.resetStartSubstream();
63 }
64
65 public void resetNextSubstream() {
66 st.resetNextSubstream();
67 }
68
73 public String toString() {
74 return "Baker transformation of " + st.toString();
75 }
76
81 public double nextDouble() {
82 double u = st.nextDouble();
83 if (u > 0.5)
84 return 2.0 * (1.0 - u);
85 else
86 return u + u;
87 }
88
93 public int nextInt(int i, int j) {
94 return i + (int) (nextDouble() * (j - i + 1.0));
95 }
96
105 public void nextArrayOfDouble(double[] u, int start, int n) {
106 st.nextArrayOfDouble(u, start, n);
107 for (int i = start; i < start + n; i++)
108 if (u[i] > 0.5)
109 u[i] = 2.0 * (1.0 - u[i]);
110 else
111 u[i] += u[i];
112 }
113
123 public void nextArrayOfInt(int i, int j, int[] u, int start, int n) {
124 for (int ii = start; ii < start + n; ii++)
125 u[ii] = nextInt(i, j);
126 }
127
128}
void nextArrayOfDouble(double[] u, int start, int n)
Calls nextArrayOfDouble (u, start, n) for the base stream, then applies the baker transformation.
int nextInt(int i, int j)
Generates a random integer in via nextDouble (in which the baker transformation is applied).
double nextDouble()
Returns the baker transformation of s.nextDouble() where s is the base stream.
void resetNextSubstream()
Reinitializes the stream to the beginning of its next substream:
void resetStartSubstream()
Reinitializes the stream to the beginning of its current substream:
void nextArrayOfInt(int i, int j, int[] u, int start, int n)
Fills up the array by calling nextInt (i, j).
String toString()
Returns a string starting with "Baker transformation of " and finishing with the result of the call t...
void resetStartStream()
Reinitializes the stream to its initial state : and are set to .
BakerTransformedStream(RandomStream stream)
Constructs a new baker transformed stream, using the random numbers from the base stream stream.
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...