• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

Public Member Functions | List of all members
KRandomSequence Class Reference

#include <krandomsequence.h>

Public Member Functions

 KRandomSequence (long lngSeed=0)
 
virtual ~KRandomSequence ()
 
 KRandomSequence (const KRandomSequence &a)
 
KRandomSequence & operator= (const KRandomSequence &a)
 
void setSeed (long lngSeed=0)
 
double getDouble ()
 
unsigned long getLong (unsigned long max)
 
bool getBool ()
 
void randomize (TQGList *list)
 
void modulate (int i)
 

Detailed Description

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 sh@as.nosp@m.tro..nosp@m.keele.nosp@m..ac..nosp@m.uk

Definition at line 39 of file krandomsequence.h.

Constructor & Destructor Documentation

◆ KRandomSequence() [1/2]

KRandomSequence::KRandomSequence ( long  lngSeed = 0)

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 tdeApp->random() instead.

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

Definition at line 32 of file krandomsequence.cpp.

◆ ~KRandomSequence()

KRandomSequence::~KRandomSequence ( )
virtual

Standard destructor.

Definition at line 42 of file krandomsequence.cpp.

◆ KRandomSequence() [2/2]

KRandomSequence::KRandomSequence ( const KRandomSequence &  a)

Copy constructor.

Definition at line 47 of file krandomsequence.cpp.

Member Function Documentation

◆ getBool()

bool KRandomSequence::getBool ( )

Get a boolean from the pseudo-random sequence.

Returns
a boolean which is either true or false

Definition at line 213 of file krandomsequence.cpp.

◆ getDouble()

double KRandomSequence::getDouble ( )

Get the next number from the pseudo-random sequence.

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

Definition at line 185 of file krandomsequence.cpp.

◆ getLong()

unsigned long KRandomSequence::getLong ( unsigned 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

Definition at line 205 of file krandomsequence.cpp.

◆ modulate()

void KRandomSequence::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
ithe sequence identified

Definition at line 168 of file krandomsequence.cpp.

◆ operator=()

KRandomSequence & KRandomSequence::operator= ( const KRandomSequence &  a)

Assignment.

Definition at line 55 of file krandomsequence.cpp.

◆ randomize()

void KRandomSequence::randomize ( TQGList *  list)

Put a list in random order.

Parameters
listthe list whose order will be modified

Definition at line 229 of file krandomsequence.cpp.

◆ setSeed()

void KRandomSequence::setSeed ( long  lngSeed = 0)

Restart the sequence based on lngSeed.

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

Definition at line 69 of file krandomsequence.cpp.


The documentation for this class was generated from the following files:
  • krandomsequence.h
  • krandomsequence.cpp

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.4
This website is maintained by Timothy Pearson.