norsys.netica
Class RandomGenerator

java.lang.Object
  |
  +--norsys.netica.RandomGenerator

public class RandomGenerator
extends java.lang.Object

A class that manages the generation of random numbers.

Since:
5.02
Version:
5.02 - April 8, 2011

Constructor Summary
RandomGenerator(java.lang.String seed, Environ env, java.lang.String options)

Creates a new object to generate pseudo-random numbers, or control Netica's internal random number generation.

 
Method Summary
 void finalize()

Removes the this RandomGenerator object and frees all its resources (e.g., memory).

 double generateRandomNumbers(double[] results, int num, java.lang.String options)

Generates num random numbers using this randomGenerator and puts them in the array result, returning the first one.

 Environ getEnviron()

Returns this RandomGenerator's environment.

 java.lang.String getState(java.lang.String options)

Returns a string that can be used as a seed to generateRandomNumbers to create a RandomGenerator that will produce exactly the same pseudo-random numbers as this randGen.

 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

public RandomGenerator (
 String  seed
 Environ  env
 String  options 
) throws NeticaException
Creates a new object to generate pseudo-random numbers, or control Netica's internal random number generation.

For ease in debugging and tracing, Netica API behaviour is always deterministic (unless non-determinism comes from multiple threads not synchronized), unless "Nondeterministic" is passed as options.

Netica API can be made to appear non-deterministic (e.g. to generate different sequences of cases with generateRandomCase) by passing in a "random" value for seed.

seed can either be a positive integer (as a string), or the result returned by getState.

options should either be null or the string "Nondeterministic". If it is the latter, seed is ignored and the random sequence will be nondeterministic.

When you are finished with the random generator object, free the resources it uses by calling DeleteRandomGen.

Parameters:
String    seed    A definition of the algorithm state of the random generator.
Environ    env    The environment that will contain this generator.
String    options    Controls behavior of the generator.

Version:

Versions 3.04 and later have this method.
In the C Version of the API, this function is named NewRandomGenerator_ns.
See Also:
finalize    To free the RandomGenerator when done with it.
getState    To obtain a seed value.
generateRandomNumbers    Use the RandomGenerator to make random numbers.
Net.generateRandomCase    Use it to control simulation.
Net.setRandomGenerator    Associate a RandomGenerator with a net.

Example:
Method Detail
public void finalize ( ) throws NeticaException
Removes the this RandomGenerator object and frees all its resources (e.g., memory).

You must not call this on a randomGenerator that was passed to setRandomGenerator.

You must not try to use or delete randomGenerator after calling this.

It is okay if randomGenerator is null (then no action is taken).

Version:

Versions 3.04 and later have this method.
In the C Version of the API, this function is named DeleteRandomGen_ns.
See Also:
RandomGenerator    To create a new RandomGenerator.

Example:
See RandomGenerator.
Overrides:
finalize in class java.lang.Object

public Environ getEnviron ( )
Returns this RandomGenerator's environment.

Version:
Versions 3.04 and later have this method.

public String getState (
 String  options 
) throws NeticaException
Returns a string that can be used as a seed to generateRandomNumbers to create a RandomGenerator that will produce exactly the same pseudo-random numbers as this randGen.

So you can save the state of a random generator to later make an equivalent generator.

The results returned are only valid until the next operation using this randGen, so you should duplicate the string returned.

The string returned will always be a null terminated C string of printing ascii characters, so it can be easily printed to a file.

Pass null for options; it is only for future expansion.

Parameters:
String    options    For future expandability. Pass null for now.

Version:

Versions 5.02 and later have this method.
In the C Version of the API, this function is named GetRandomGenState_ns.
See Also:
RandomGenerator    Create a new RandomGenerator with the value returned.

Example:
See RandomGenerator.

public double generateRandomNumbers (
 double[ ]  results
 int  num
 String  options 
) throws NeticaException
Generates num random numbers using this randomGenerator and puts them in the array result, returning the first one.

The numbers will be between 0 (inclusive) and 1 (exclusive), that is, from the interval [0,1).

results should be an array with enough room to store the required numbers; it may be null if you are just using the number returned.

This randomGenerator will be left in a state to generate further random numbers, or it can be passed to any Netica API function that takes a RandomGenerator.

Pass null for options; it is only for future expansion.

Parameters:
double[]    results    An array with enough room to store the required numbers; it may be null.
int    num    The quantity of numbers to generate.
String    options    Controls behavior of the generation.

Version:

Versions 5.02 and later have this method.
In the C Version of the API, this function is named GenerateRandomNumbers_ns.
See Also:
RandomGenerator    To create a new RandomGenerator.

Example:
See RandomGenerator.