com.rubecula.util.random
Class Randomizer

java.lang.Object
  extended by com.rubecula.util.random.Randomizer
All Implemented Interfaces:
java.io.Serializable, org.apache.commons.math.random.RandomGenerator
Direct Known Subclasses:
Randomizer_TS

public class Randomizer
extends java.lang.Object
implements org.apache.commons.math.random.RandomGenerator

Title: Randomizer

Description: this class extends RandomGenerator to play a kind of roulette wheel game. A set of relative frequencies is defined for each "band". The result of calling nextIndex() is to return an index into the band. Obviously, the higher the frequency of the band, the more likely the index is going to point to that particular band.
For the roulette wheel game, there would be 37 (38 in the USA) bands defined with equal frequency. Unless of course you were setting up a crooked roulette wheel, in which case you would increase (slightly, presumably) the frequency of your favorite band.

Copyright: Copyright (c) 2003

Company: Rubecula Software, LLC

Version:
1.0 TODO consider extending AToString
Author:
Robin Hillyard
See Also:
Serialized Form

Constructor Summary
Randomizer()
          Deprecated.  
Randomizer(int[] bands)
          Deprecated.  
Randomizer(int[] bands, boolean reseed)
          Deprecated.  
Randomizer(int[] bands, long seed)
          Deprecated.  
Randomizer(long seed)
          Deprecated.  
Randomizer(org.apache.commons.math.random.RandomGenerator random)
          Construct a randomizer with an empty array of band widths, and using the specified random number generator.
Randomizer(org.apache.commons.math.random.RandomGenerator random, int[] bands)
          Construct a randomizer with an array of band widths, and using the specified random number generator.
Randomizer(org.apache.commons.math.random.RandomGenerator random, int[] bands, boolean reseed)
          Primary constructor.
 
Method Summary
 int[] getBands()
           
 int getTotal()
           
 boolean nextBoolean()
           
 void nextBytes(byte[] bytes)
           
 double nextDouble()
           
 float nextFloat()
           
 double nextGaussian()
           
 int nextIndex()
          The behavior of this method depends on whether any bands were defined for this randomizer.
 int nextInt()
           
 int nextInt(int n)
           
 long nextLong()
           
 void setBands(int[] bands)
           
 void setOdds(int odds)
           
 void setSeed(long seed)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Randomizer

@Deprecated
public Randomizer()
Deprecated. 

Secondary constructor for randomizer with an empty array of band widths. The Random Number Generator used will be an instance of Random_Standard with no specified seed. The RNG will not be reseeded after each call.


Randomizer

@Deprecated
public Randomizer(int[] bands)
Deprecated. 

Secondary constructor for randomizer with an array of band widths. The Random Number Generator used will be an instance of Random_Standard with no specified seed. The RNG will not be reseeded after each call.

Parameters:
bands - An array of longs which give the relative frequencies desired for each band.

Randomizer

@Deprecated
public Randomizer(int[] bands,
                             boolean reseed)
Deprecated. 

Secondary constructor for randomizer with an array of band widths. The Random Number Generator used will be an instance of Random_Standard with no specified seed.

Parameters:
bands - An array of longs which give the relative frequencies desired for each band.
reseed - true if the randomizer is to be reseeded before every randomizing call. This is good when the calls are made according to e.g. clicks in a user interface or updates from a web service. Otherwise, the numbers follow a pseudo-random number generator sequence.

Randomizer

@Deprecated
public Randomizer(int[] bands,
                             long seed)
Deprecated. 

Secondary constructor for randomizer with an array of band widths. The Random Number Generator used will be an instance of Random_Standard with the specified seed. The RNG will not be reseeded after each call.

Parameters:
bands - An array of longs which give the relative frequencies desired for each band.
seed - the seed for the first random number.

Randomizer

@Deprecated
public Randomizer(long seed)
Deprecated. 

Secondary constructor for randomizer with an empty array of band widths. The Random Number Generator used will be an instance of Random_Standard with the specified seed. The RNG will not be reseeded after each call.

Parameters:
seed - the seed for the first random number.

Randomizer

public Randomizer(org.apache.commons.math.random.RandomGenerator random)
Construct a randomizer with an empty array of band widths, and using the specified random number generator. The RNG will not be reseeded after each call.

Parameters:
random - a random number generator.

Randomizer

public Randomizer(org.apache.commons.math.random.RandomGenerator random,
                  int[] bands)
Construct a randomizer with an array of band widths, and using the specified random number generator. The RNG will not be reseeded after each call.

Parameters:
random -
bands - An array of longs which give the relative frequencies desired for each band.

Randomizer

public Randomizer(org.apache.commons.math.random.RandomGenerator random,
                  int[] bands,
                  boolean reseed)
Primary constructor.

Parameters:
random - a random number generator.
bands -
reseed - if true, the RNG will be reseeded after each call (using the system clock).
Method Detail

getBands

public int[] getBands()
Returns:
the array field _Bands

getTotal

public int getTotal()
Returns:
the field _Total

nextBoolean

public boolean nextBoolean()
Specified by:
nextBoolean in interface org.apache.commons.math.random.RandomGenerator
See Also:
RandomGenerator.nextBoolean()

nextBytes

public void nextBytes(byte[] bytes)
Specified by:
nextBytes in interface org.apache.commons.math.random.RandomGenerator
See Also:
RandomGenerator.nextBytes(byte[])

nextDouble

public double nextDouble()
Specified by:
nextDouble in interface org.apache.commons.math.random.RandomGenerator
See Also:
RandomGenerator.nextDouble()

nextFloat

public float nextFloat()
Specified by:
nextFloat in interface org.apache.commons.math.random.RandomGenerator
See Also:
RandomGenerator.nextFloat()

nextGaussian

public double nextGaussian()
Specified by:
nextGaussian in interface org.apache.commons.math.random.RandomGenerator
See Also:
RandomGenerator.nextGaussian()

nextIndex

public int nextIndex()
The behavior of this method depends on whether any bands were defined for this randomizer. If bands were defined, the result is an index into the bands. If bands were not defined, the result is a number uniformly distributed between 0 and Integer.MAX_VALUE. In both cases, the superclass method RandomGenerator.nextInt(int) is called.

Returns:
the "index" as defined above.

nextInt

public int nextInt()
Specified by:
nextInt in interface org.apache.commons.math.random.RandomGenerator
See Also:
RandomGenerator.nextInt()

nextInt

public int nextInt(int n)
Specified by:
nextInt in interface org.apache.commons.math.random.RandomGenerator
See Also:
RandomGenerator.nextInt(int)

nextLong

public long nextLong()
Specified by:
nextLong in interface org.apache.commons.math.random.RandomGenerator
See Also:
RandomGenerator.nextLong()

setBands

public void setBands(int[] bands)
Parameters:
bands -

setOdds

public void setOdds(int odds)
Parameters:
odds - the odds.

setSeed

public void setSeed(long seed)
Specified by:
setSeed in interface org.apache.commons.math.random.RandomGenerator
See Also:
RandomGenerator.setSeed(long)


Copyright © 2010 Rubecula Software, LLC. All Rights Reserved.