org.kde.koala
Class KRandomSequence

java.lang.Object
  extended by org.kde.koala.KRandomSequence
All Implemented Interfaces:
org.kde.qt.QtSupport

public class KRandomSequence
extends java.lang.Object
implements org.kde.qt.QtSupport

A class to create a pseudo-random sequence Given a seed number, this class will produce a sequence of pseudo-random numbers. This would typically be used in applications like games. In general, you should instantiate a KRandomSequence object and pass along your seed number in the constructor. From then on, simply call getDouble() or getLong() to obtain the next number in the sequence.

Author:
Sean Harmer

Constructor Summary
  KRandomSequence()
           
protected KRandomSequence(java.lang.Class dummy)
           
  KRandomSequence(KRandomSequence a)
          Copy constructor
  KRandomSequence(long lngSeed)
          Creates a pseudo-random sequence based on the seed lngSeed.
 
Method Summary
 void dispose()
          Delete the wrapped C++ instance ahead of finalize()
protected  void finalize()
          Deletes the wrapped C++ instance
 boolean getBool()
          Get a booleanean from the pseudo-random sequence.
 double getDouble()
          Get the next number from the pseudo-random sequence.
 long getLong(long max)
          Get the next number from the pseudo-random sequence.
 boolean isDisposed()
          Has the wrapped C++ instance been deleted?
 void modulate(int i)
          Modulate the random sequence.
 void setSeed()
           
 void setSeed(long lngSeed)
          Restart the sequence based on lngSeed.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KRandomSequence

protected KRandomSequence(java.lang.Class dummy)

KRandomSequence

public KRandomSequence(long lngSeed)
Creates a pseudo-random sequence based on the seed lngSeed. A Pseudo-random sequence is different for each seed but can be reproduced by starting the sequence with the same seed. If you need a single value which needs to be unpredictable, you need to use kapp.random() instead.

Parameters:
lngSeed - Seed to initialize the sequence with. If lngSeed is 0, the sequence is initialized with a value from KApplication.random().

KRandomSequence

public KRandomSequence()

KRandomSequence

public KRandomSequence(KRandomSequence a)
Copy constructor

Method Detail

setSeed

public void setSeed(long lngSeed)
Restart the sequence based on lngSeed.

Parameters:
lngSeed - Seed to initialize the sequence with. If lngSeed is 0, the sequence is initialized with a value from KApplication.random().

setSeed

public void setSeed()

getDouble

public double getDouble()
Get the next number from the pseudo-random sequence.

Returns:
a pseudo-random double value between [0,1[

getLong

public long getLong(long max)
Get the next number from the pseudo-random sequence.

Returns:
a pseudo-random integer value between [0, max[ with 0 <= max < 1.000.000

getBool

public boolean getBool()
Get a booleanean from the pseudo-random sequence.

Returns:
a boolean which is either true or false

modulate

public void modulate(int i)
Modulate the random sequence. If S(i) is the sequence of numbers that will follow given the current state after calling modulate(i), then S(i) != S(j) for i != j and S(i) == S(j) for i == j. This can be useful in game situation where "undo" restores the state of the random sequence. If the game modulates the random sequence with the move chosen by the player, the random sequence will be identical whenever the player "redo"-s his or hers original move, but different when the player chooses another move. With this scenario "undo" can no longer be used to repeat a certain move over and over again until the computer reacts with a favorable response or to predict the response for a certain move based on the response to another move.

Parameters:
i - the sequence identified

finalize

protected void finalize()
                 throws java.lang.InternalError
Deletes the wrapped C++ instance

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.InternalError

dispose

public void dispose()
Delete the wrapped C++ instance ahead of finalize()


isDisposed

public boolean isDisposed()
Has the wrapped C++ instance been deleted?