• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

Public Member Functions | List of all members
KRandomSequence Class Reference

#include <KRandomSequence>

Public Member Functions

 KRandomSequence (long lngSeed=0)
 
 KRandomSequence (const KRandomSequence &a)
 
virtual ~KRandomSequence ()
 
bool getBool ()
 
double getDouble ()
 
unsigned long getLong (unsigned long max)
 
void modulate (int i)
 
KRandomSequence & operator= (const KRandomSequence &a)
 
template<typename T >
void randomize (QList< T > &list)
 
void setSeed (long lngSeed=0)
 

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 40 of file krandomsequence.h.

Constructor & Destructor Documentation

KRandomSequence::KRandomSequence ( long  lngSeed = 0)
explicit

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

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

Definition at line 42 of file krandomsequence.cpp.

KRandomSequence::~KRandomSequence ( )
virtual

Standard destructor.

Definition at line 48 of file krandomsequence.cpp.

KRandomSequence::KRandomSequence ( const KRandomSequence &  a)

Copy constructor.

Definition at line 53 of file krandomsequence.cpp.

Member Function Documentation

bool KRandomSequence::getBool ( )

Get a boolean from the pseudo-random sequence.

Returns
a boolean which is either true or false

Definition at line 215 of file krandomsequence.cpp.

double KRandomSequence::getDouble ( )

Get the next number from the pseudo-random sequence.

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

Definition at line 187 of file krandomsequence.cpp.

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 207 of file krandomsequence.cpp.

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 170 of file krandomsequence.cpp.

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

Assignment.

Definition at line 58 of file krandomsequence.cpp.

template<typename T >
void KRandomSequence::randomize ( QList< T > &  list)
inline

Put a list in random order.

Since KDE 4.11, this function uses a more efficient algorithm (Fisher-Yates). Therefore, the order of the items in the randomized list is different from the one in earlier versions if the same seed value is used for the random sequence.

Parameters
listthe list whose order will be modified
Note
modifies the list in place

Definition at line 112 of file krandomsequence.h.

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 KRandom::random().

Definition at line 71 of file krandomsequence.cpp.


The documentation for this class was generated from the following files:
  • krandomsequence.h
  • krandomsequence.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:13 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal