001: /*
002: * Copyright 2005 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.math.random;
017:
018: /**
019: * Interface extracted from <code>java.util.Random</code>. This interface is
020: * implemented by {@link AbstractRandomGenerator}.
021: *
022: * @since 1.1
023: * @version $Revision:$ $Date$
024: */
025: public interface RandomGenerator {
026:
027: /**
028: * Sets the seed of the underyling random number generator using a
029: * <code>long</code> seed. Sequences of values generated starting with the
030: * same seeds should be identical.
031: *
032: * @param seed the seed value
033: */
034: void setSeed(long seed);
035:
036: /**
037: * Generates random bytes and places them into a user-supplied
038: * byte array. The number of random bytes produced is equal to
039: * the length of the byte array.
040: *
041: * @param bytes the non-null byte array in which to put the
042: * random bytes
043: */
044: void nextBytes(byte[] bytes);
045:
046: /**
047: * Returns the next pseudorandom, uniformly distributed <code>int</code>
048: * value from this random number generator's sequence.
049: * All 2<font size="-1"><sup>32</sup></font> possible <tt>int</tt> values
050: * should be produced with (approximately) equal probability.
051: *
052: * @return the next pseudorandom, uniformly distributed <code>int</code>
053: * value from this random number generator's sequence
054: */
055: int nextInt();
056:
057: /**
058: * Returns a pseudorandom, uniformly distributed <tt>int</tt> value
059: * between 0 (inclusive) and the specified value (exclusive), drawn from
060: * this random number generator's sequence.
061: *
062: * @param n the bound on the random number to be returned. Must be
063: * positive.
064: * @return a pseudorandom, uniformly distributed <tt>int</tt>
065: * value between 0 (inclusive) and n (exclusive).
066: * @throws IllegalArgumentException if n is not positive.
067: */
068: int nextInt(int n);
069:
070: /**
071: * Returns the next pseudorandom, uniformly distributed <code>long</code>
072: * value from this random number generator's sequence. All
073: * 2<font size="-1"><sup>64</sup></font> possible <tt>long</tt> values
074: * should be produced with (approximately) equal probability.
075: *
076: * @return the next pseudorandom, uniformly distributed <code>long</code>
077: *value from this random number generator's sequence
078: */
079: long nextLong();
080:
081: /**
082: * Returns the next pseudorandom, uniformly distributed
083: * <code>boolean</code> value from this random number generator's
084: * sequence.
085: *
086: * @return the next pseudorandom, uniformly distributed
087: * <code>boolean</code> value from this random number generator's
088: * sequence
089: */
090: boolean nextBoolean();
091:
092: /**
093: * Returns the next pseudorandom, uniformly distributed <code>float</code>
094: * value between <code>0.0</code> and <code>1.0</code> from this random
095: * number generator's sequence.
096: *
097: * @return the next pseudorandom, uniformly distributed <code>float</code>
098: * value between <code>0.0</code> and <code>1.0</code> from this
099: * random number generator's sequence
100: */
101: float nextFloat();
102:
103: /**
104: * Returns the next pseudorandom, uniformly distributed
105: * <code>double</code> value between <code>0.0</code> and
106: * <code>1.0</code> from this random number generator's sequence.
107: *
108: * @return the next pseudorandom, uniformly distributed
109: * <code>double</code> value between <code>0.0</code> and
110: * <code>1.0</code> from this random number generator's sequence
111: */
112: double nextDouble();
113:
114: /**
115: * Returns the next pseudorandom, Gaussian ("normally") distributed
116: * <code>double</code> value with mean <code>0.0</code> and standard
117: * deviation <code>1.0</code> from this random number generator's sequence.
118: *
119: * @return the next pseudorandom, Gaussian ("normally") distributed
120: * <code>double</code> value with mean <code>0.0</code> and
121: * standard deviation <code>1.0</code> from this random number
122: * generator's sequence
123: */
124: double nextGaussian();
125: }
|