bcds.tools.random
Class RndArea

java.lang.Object
  extended by bcds.tools.random.RndGenBase
      extended by bcds.tools.random.RndArea
All Implemented Interfaces:
RndGen

public class RndArea
extends RndGenBase
implements RndGen

Selects random values from a list, where the probability of being selected depends on the elements' "proportion" (or share) within the group. The share of the element is a float value that states its relative frequency. Schematically, given

   V = [1.5, 3, 5.5]                    // Choose between two elements.
   rnd = new RndArea(V)
 
the second element (in position 1) will appear aproximately twice as often as the first one when rnd's next method is repeatedly called.

Author:
Juan Segovia S.

Constructor Summary
RndArea(java.util.ArrayList<T1> val_prop)
          Creates a new instance with the elements frequency given in val_prop.
RndArea(java.util.Random rnd, java.util.ArrayList<T1> val_prop)
          Creates a new instance.
 
Method Summary
static void main(java.lang.String[] args)
           
 double next()
          Returns an index in the range [0, |val_prop|) to indicate which element of the list is selected.
 
Methods inherited from class bcds.tools.random.RndGenBase
getRandomGen, setRandomGen
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface bcds.tools.random.RndGen
getRandomGen, setRandomGen
 

Constructor Detail

RndArea

public RndArea(java.util.ArrayList<T1> val_prop)
Creates a new instance with the elements frequency given in val_prop. Uses the default randomness source.

Note that val_prop gives the frequency of each element. After the instantiation, this parameter is never used again (its values are stored internally in this object).


RndArea

public RndArea(java.util.Random rnd,
               java.util.ArrayList<T1> val_prop)
Creates a new instance. It is the same as RndArea(ArrayList) but sets the randomness source to rnd.

Method Detail

next

public double next()
Returns an index in the range [0, |val_prop|) to indicate which element of the list is selected.

Specified by:
next in interface RndGen

main

public static void main(java.lang.String[] args)