cgul_random_xorwow32_cxx Class Reference

C++ bindings for cgul_random_xorwow32 More...

#include <cgul_random_xorwow32_cxx.h>

Collaboration diagram for cgul_random_xorwow32_cxx:
Collaboration graph

Public Member Functions

 cgul_random_xorwow32_cxx ()
 
 cgul_random_xorwow32_cxx (cgul_uint32_t seed)
 
 cgul_random_xorwow32_cxx (cgul_uint32_t *seeds)
 
 cgul_random_xorwow32_cxx (cgul_random_xorwow32_t rhs)
 
virtual ~cgul_random_xorwow32_cxx ()
 
virtual cgul_uint32_t next ()
 
virtual cgul_uint32_t next_in_range (cgul_uint32_t range_max)
 
virtual double next_in_unit ()
 
virtual cgul_random_xorwow32_t get_obj () const
 
virtual cgul_random_xorwow32_t take_obj ()
 
virtual void set_obj (cgul_random_xorwow32_t rhs)
 

Static Public Member Functions

static void allocate_seed_array (cgul_uint32_t **v, unsigned int *v_count)
 

Detailed Description

This class provides the C++ bindings for cgul_random_xorwow32. The main purpose of this class is to convert the C-style function calls and exception handling into C++-style function calls and exception handling.

Constructor & Destructor Documentation

§ cgul_random_xorwow32_cxx() [1/4]

cgul_random_xorwow32_cxx::cgul_random_xorwow32_cxx ( )
inline

Default constructor that creates a new object seeding it with the value returned by time(), i.e., the 32-bit seconds since the epoch. The caller is responsible for arranging for delete to be called on the object. If memory cannot be allocated, and an exception is thrown.

References cgul_random_xorwow32__new().

Referenced by set_obj().

§ cgul_random_xorwow32_cxx() [2/4]

cgul_random_xorwow32_cxx::cgul_random_xorwow32_cxx ( cgul_uint32_t  seed)
inline

Construct a new object seeding it with seed. The caller is responsible for arranging for delete to be called on the object. If memory cannot be allocated, an exception is thrown.

Parameters
[in]seedseed value

References cgul_random_xorwow32__new_from_seed().

§ cgul_random_xorwow32_cxx() [3/4]

cgul_random_xorwow32_cxx::cgul_random_xorwow32_cxx ( cgul_uint32_t *  seeds)
inline

Construct a new object by seeding it with the seeds array. This is the correct way to create a new object; however it can be difficult to acquire the requisite entropy to fill the entire array. The caller is responsible for arranging for delete to be called on the object. If memory cannot be allocated or if all the seed values are zero, an exception is thrown.

The caller is responsible for making sure seeds has the correct number of elements. The easiest way to do this is by using allocate_seed_array() to allocate the array and get its size.

Parameters
[in]seedsarray of 32-bit values used to seed the PRNG
See also
allocate_seed_array()

References cgul_random_xorwow32__new_from_seed_array().

§ cgul_random_xorwow32_cxx() [4/4]

cgul_random_xorwow32_cxx::cgul_random_xorwow32_cxx ( cgul_random_xorwow32_t  rhs)
inline

Create a new cgul_random_xorwow32_cxx object by wrapping an existing cgul_random_xorwow32 object.

Parameters
[in]rhsright-hand side

§ ~cgul_random_xorwow32_cxx()

virtual cgul_random_xorwow32_cxx::~cgul_random_xorwow32_cxx ( )
inlinevirtual

This method frees all internally allocated memory. Do not attempt to use the object after calling this method.

References cgul_random_xorwow32__delete().

Member Function Documentation

§ allocate_seed_array()

static void cgul_random_xorwow32_cxx::allocate_seed_array ( cgul_uint32_t **  v,
unsigned int *  v_count 
)
inlinestatic

This function allocates and returns an array of 32-bit seed values v where each element of the array is initialized to zero. The total number of 32-bit seed values in the array is returned in v_count. The caller should fill the array with true random values and create a new PRNG seeded with the values by calling the correct constructor. The caller is responsible for calling free(*v). If an error occurs, an exception is thrown.

Parameters
[out]vuninitialized array of 32-bit seed values
[out]v_countcount of the number of 32-bit values in v

References cgul_random_xorwow32__allocate_seed_array().

§ next()

virtual cgul_uint32_t cgul_random_xorwow32_cxx::next ( )
inlinevirtual

Return the next element in the pseudo-random number sequence. The random numbers returned are 32 bits wide and should have a period of (2^192 - 2^32).

Returns
next element in the random number sequence
See also
next_in_range()
next_in_unit()

References cgul_random_xorwow32__next().

§ next_in_range()

virtual cgul_uint32_t cgul_random_xorwow32_cxx::next_in_range ( cgul_uint32_t  range_max)
inlinevirtual

If the value returned by next() is not the exact range that is needed, this method can limit the return value to [0, range_max). If range_max is zero, an exception is thrown.

This function should avoid the very small round off error associated with just scaling the value returned by next_in_unit(); however, this function is much slower.

Parameters
[in]range_maxexclusive limit on the maximum value returned
Returns
next element in the random number sequence

References cgul_random_xorwow32__next_in_range().

§ next_in_unit()

virtual double cgul_random_xorwow32_cxx::next_in_unit ( )
inlinevirtual

Return the next element in the pseudo-random number sequence as type double on the range [0 - 1).

Returns
next element in the random number sequence

References cgul_random_xorwow32__next_in_unit().

§ get_obj()

virtual cgul_random_xorwow32_t cgul_random_xorwow32_cxx::get_obj ( ) const
inlinevirtual

Get the underlying cgul_random_xorwow32 object.

Returns
underlying object

§ take_obj()

virtual cgul_random_xorwow32_t cgul_random_xorwow32_cxx::take_obj ( )
inlinevirtual

Take the underlying cgul_random_xorwow32 object. This means the underlying object will not be deleted when the wrapper goes out of scope. Also, because you have taken the underlying object, no other methods should be called on this wrapper's instance. Lastly, after taking the underlying object, it is the caller's responsibility to delete the underlying object by calling cgul_random_xorwow32__delete().

Returns
underlying object

§ set_obj()

virtual void cgul_random_xorwow32_cxx::set_obj ( cgul_random_xorwow32_t  rhs)
inlinevirtual

Set the new underlying object to rhs. This causes the old underlying object to be deleted which invalidates any outstanding pointers to or iterators for the old underlying object.

This instance takes ownership of rhs which means rhs will be automatically deleted when the C++ wrapper is deleted. To prevent automatic deletion of rhs, call take_obj() when the C++ wrapper is no longer needed.

Parameters
[in]rhsright-hand side

References cgul_random_xorwow32__delete(), and cgul_random_xorwow32_cxx().


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