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