SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWRandGenerator Class Reference

Generates random numbers uniformly distributed over the interval [0, 1]. More...

#include <rw/randgen.h>

Public Member Functions

 RWRandGenerator ()
 
 RWRandGenerator (const RWRandGenerator &x)
 
 RWRandGenerator (long seed)
 
void deepenShallowCopy ()
 
double operator() ()
 
RWRandGeneratoroperator= (const RWRandGenerator &x)
 
void printOn (std::ostream &s) const
 
void reference (const RWRandGenerator &x)
 
void restart ()
 
void restart (long seed)
 
void restoreFrom (RWFile &)
 
void restoreFrom (RWvistream &)
 
void saveOn (RWFile &) const
 
void saveOn (RWvostream &) const
 
void scanFrom (std::istream &s)
 

Related Symbols

(Note that these are not member symbols.)

std::ostream & operator<< (std::ostream &s, const RWRandGenerator &rgen)
 
std::istream & operator>> (std::istream &s, RWRandGenerator &rgen)
 

Detailed Description

Class RWRandGenerator generates random numbers uniformly distributed over the interval [0, 1]. RWRandGenerator objects can be independent or share state with each other. The Essential Math Module contains a global default state that is shared by all generators created with the default constructor. Using the default generator state does not guarantee repeatable sequences, even if you restart() it using a specific seed. This is because the global state may be shared among several applications in a multithreaded environment. There is no protection against multiple threads of control using the global default state at the same time. To achieve repeatable sequences, you must construct a generator with a specific seed value and use the generator for random number generation.

Synopsis
#include <rw/randgen.h>
Generates random numbers uniformly distributed over the interval [0, 1].
Definition randgen.h:61

Constructor & Destructor Documentation

◆ RWRandGenerator() [1/3]

RWRandGenerator::RWRandGenerator ( )

Constructs a generator with the shared global default state.

◆ RWRandGenerator() [2/3]

RWRandGenerator::RWRandGenerator ( long seed)

Constructs a generator with specified initial seed. The generator has its own state.

◆ RWRandGenerator() [3/3]

RWRandGenerator::RWRandGenerator ( const RWRandGenerator & x)

Constructs a copy of x. The generators share state.

Member Function Documentation

◆ deepenShallowCopy()

void RWRandGenerator::deepenShallowCopy ( )

Makes the state independent, but doesn't change it.

◆ operator()()

double RWRandGenerator::operator() ( )

Returns a random double in [0, 1].

◆ operator=()

RWRandGenerator & RWRandGenerator::operator= ( const RWRandGenerator & x)

Sets state to argument's state.

◆ printOn()

void RWRandGenerator::printOn ( std::ostream & s) const

Outputs a summary of self's internal state on ostream s.

◆ reference()

void RWRandGenerator::reference ( const RWRandGenerator & x)

Sets state to argument's state.

◆ restart() [1/2]

void RWRandGenerator::restart ( )

Restarts the generator with a random seed.

◆ restart() [2/2]

void RWRandGenerator::restart ( long seed)

Restarts the generator with the specified seed.

◆ restoreFrom() [1/2]

void RWRandGenerator::restoreFrom ( RWFile & )

Restores internal state of self from an RWFile.

◆ restoreFrom() [2/2]

void RWRandGenerator::restoreFrom ( RWvistream & )

Restores internal state of self from a virtual stream.

◆ saveOn() [1/2]

void RWRandGenerator::saveOn ( RWFile & ) const

Stores internal state of self in a binary format to an RWFile.

◆ saveOn() [2/2]

void RWRandGenerator::saveOn ( RWvostream & ) const

Stores internal state of self to a virtual stream.

◆ scanFrom()

void RWRandGenerator::scanFrom ( std::istream & s)

Inputs an internal state from istream s to self.

Friends And Related Symbol Documentation

◆ operator<<()

std::ostream & operator<< ( std::ostream & s,
const RWRandGenerator & rgen )
related

Outputs a summary of the internal state of rgen on ostream s.

◆ operator>>()

std::istream & operator>> ( std::istream & s,
RWRandGenerator & rgen )
related

Inputs an internal state from istream s to rgen.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.