|
SoftNet-Consult Java Utility Library | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.Random com.softnetConsult.utils.random.FastRandom
public class FastRandom
Provides a fast pseudorandom number generator by trading off memory for speed.
Objects of this class generate a large number of random numbers when
they are created and reuse them throughout the life-time. For many
applications the repetition effect does not significantly affect the
quality of the random series given that the size of the buffer sufficiently
large. This class is usefull when a time-critical application requires a
very large number of random numbers; a slight delay for the buffer creation
at the start saves a lot of time during the runtime.
Note that the current version of this class accelerates only the generation of
pseudorandom values of types boolean
, double
and int
:
pseudorandom values are pre-generated and cached, pseudorandom values of other
types are generated on the fly by passing the nextXXX()
-calls to the
default Java pseudorandom number generator.
This product includes software developed by the
SoftNet-Consult Java Utility Library project and its contributors.
(http://java-tools.sourceforge.net)
Copyright (c) 2007-2008 SoftNet-Consult.
Copyright (c) 2007-2008 G. Paperin.
All rights reserved.
File: FastRandom.java
Library API version: "2.02"
Java compliance version: "1.5"
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following terms and conditions are met:
1. Redistributions of source code must retain the above
acknowledgement of the SoftNet-Consult Java Utility Library project, the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above acknowledgement of the
SoftNet-Consult Java Utility Library project, the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
3. All advertising materials mentioning features or use of this software or any derived
software must display the following acknowledgement:
This product includes software developed by the SoftNet-Consult Java Utility Library
project and its contributors.
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Random
,
Serialized FormField Summary | |
---|---|
private boolean[] |
booleanBuffer
The buffer for random booleans. |
private int |
booleanCursor
Cursor for the boolean random numbers buffer. |
static int |
defaultBooleanBufferSize
Default buffer size for random booleans. |
static int |
defaultDoubleBufferSize
Default buffer size for random doubles. |
static int |
defaultIntBufferSize
Default buffer size for random ints. |
private double[] |
doubleBuffer
The buffer for random doubles. |
private int |
doubleCursor
Cursor for the double random numbers buffer. |
private static boolean |
generateDebugPrintout
Used internally for debug purposes. |
private int[] |
intBuffer
The buffer for random ints. |
private int |
intCursor
Cursor for the int random numbers buffer. |
private boolean |
ready
Flag to show that this object has readily initialised. |
Constructor Summary | |
---|---|
FastRandom()
Creates a new FastRandom with default buffer sizes. |
|
FastRandom(int bufferSize)
Creates a new FastRandom with buffers of the specified size. |
|
FastRandom(int booleanBufferSize,
int doubleBufferSize,
int intBufferSize)
Creates a new FastRandom with buffers of the specified size. |
|
FastRandom(long seed)
Creates a new FastRandom with default buffer sizes and a specified random seed. |
|
FastRandom(long seed,
int bufferSize)
Creates a new FastRandom with buffers of the specified size a specified random seed. |
|
FastRandom(long seed,
int booleanBufferSize,
int doubleBufferSize,
int intBufferSize)
Creates a new FastRandom with buffers of the specified size a specified random seed. |
Method Summary | |
---|---|
private void |
createBuffers(int booleanBufferSize,
int doubleBufferSize,
int intBufferSize)
Allocates the random buffer arrays. |
boolean |
nextBoolean()
Returns the next pseudorandom boolean . |
double |
nextDouble()
Returns the next pseudorandom double . |
int |
nextInt()
Returns the next pseudorandom int . |
private void |
resetBuffers()
Used internally to fill the pseudorandom numbers buffers with values. |
void |
setSeed(long seed)
Sets the seed of this random number generator and then re-computes all buffers. |
Methods inherited from class java.util.Random |
---|
next, nextBytes, nextFloat, nextGaussian, nextInt, nextLong |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final boolean generateDebugPrintout
public static final int defaultBooleanBufferSize
public static final int defaultDoubleBufferSize
public static final int defaultIntBufferSize
private boolean[] booleanBuffer
private double[] doubleBuffer
private int[] intBuffer
private int booleanCursor
private int doubleCursor
private int intCursor
private boolean ready
Constructor Detail |
---|
public FastRandom()
FastRandom
with default buffer sizes.
public FastRandom(long seed)
FastRandom
with default buffer sizes and a specified random seed.
seed
- Inital random seed.public FastRandom(int bufferSize)
FastRandom
with buffers of the specified size.
bufferSize
- The size for the random numbers buffers.public FastRandom(long seed, int bufferSize)
FastRandom
with buffers of the specified size a specified random seed.
seed
- Inital random seed.bufferSize
- The size for the random numbers buffers.public FastRandom(int booleanBufferSize, int doubleBufferSize, int intBufferSize)
FastRandom
with buffers of the specified size.
booleanBufferSize
- The size for the random boolean
numbers buffer.doubleBufferSize
- The size for the random double
numbers buffer.intBufferSize
- The size for the random int
numbers buffer.public FastRandom(long seed, int booleanBufferSize, int doubleBufferSize, int intBufferSize)
FastRandom
with buffers of the specified size a specified random seed.
seed
- Inital random seed.booleanBufferSize
- The size for the random boolean
numbers buffer.doubleBufferSize
- The size for the random double
numbers buffer.intBufferSize
- The size for the random int
numbers buffer.Method Detail |
---|
private void createBuffers(int booleanBufferSize, int doubleBufferSize, int intBufferSize)
booleanBufferSize
- The size for the random boolean
numbers buffer.doubleBufferSize
- The size for the random double
numbers buffer.intBufferSize
- The size for the random int
numbers buffer.public void setSeed(long seed)
setSeed
in class java.util.Random
seed
- Inital random seed.Random.setSeed(long)
public boolean nextBoolean()
boolean
.
The buffered random booleans are used as source.
Once the buffer has been used up, it is used again from the start.
nextBoolean
in class java.util.Random
boolean
.Random.nextBoolean()
public double nextDouble()
double
.
The buffered random doubles are used as source.
Once the buffer has been used up, it is used again from the start.
nextDouble
in class java.util.Random
double
.Random.nextDouble()
public int nextInt()
int
.
The buffered random ints are used as source.
Once the buffer has been used up, it is used again from the start.
nextInt
in class java.util.Random
int
.Random.nextInt()
private void resetBuffers()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |