Shadowrun: Awakened 29 September 2011 - Build 871
Public Member Functions
cat::IRandom Class Reference

#include <IRandom.hpp>

Inheritance diagram for cat::IRandom:

List of all members.

Public Member Functions

virtual u32 Generate ()=0
virtual void Generate (void *buffer, int bytes)=0
u32 GenerateUnbiased (u32 low, u32 high)
virtual ~IRandom ()

Detailed Description

Definition at line 39 of file IRandom.hpp.


Constructor & Destructor Documentation

virtual cat::IRandom::~IRandom ( ) [inline, virtual]

Definition at line 42 of file IRandom.hpp.

{}

Member Function Documentation

virtual u32 cat::IRandom::Generate ( ) [pure virtual]

Implemented in cat::FortunaOutput, and cat::MersenneTwister.

Referenced by GenerateUnbiased().

virtual void cat::IRandom::Generate ( void *  buffer,
int  bytes 
) [pure virtual]
u32 cat::IRandom::GenerateUnbiased ( u32  low,
u32  high 
) [inline]

Definition at line 52 of file IRandom.hpp.

References Generate().

    {
        u32 range = high - low;

        // Round range up to the next pow(2)-1 using a Stanford Bit Twiddling Hack
        u32 v = range - 1;
        v |= v >> 1;
        v |= v >> 2;
        v |= v >> 4;
        v |= v >> 8;
        v |= v >> 16;

        // Generate an unbiased random number in the inclusive range [0..(high-low)]
        u32 x;
        do x = Generate() & v;
        while (x > range);

        return low + x;
    }

The documentation for this class was generated from the following file:

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net