C++ bindings for cgul_random_mt32
More...
#include <cgul_random_mt32_cxx.h>
This class provides the C++ bindings for cgul_random_mt32
. 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.
§ cgul_random_mt32_cxx() [1/4]
cgul_random_mt32_cxx::cgul_random_mt32_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_mt32__new().
Referenced by set_obj().
§ cgul_random_mt32_cxx() [2/4]
cgul_random_mt32_cxx::cgul_random_mt32_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
-
References cgul_random_mt32__new_from_seed().
§ cgul_random_mt32_cxx() [3/4]
cgul_random_mt32_cxx::cgul_random_mt32_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] | seeds | array of 32-bit values used to seed the PRNG |
- See also
- allocate_seed_array()
References cgul_random_mt32__new_from_seed_array().
§ cgul_random_mt32_cxx() [4/4]
Create a new cgul_random_mt32_cxx
object by wrapping an existing cgul_random_mt32
object.
- Parameters
-
§ ~cgul_random_mt32_cxx()
virtual cgul_random_mt32_cxx::~cgul_random_mt32_cxx |
( |
| ) |
|
|
inlinevirtual |
This method frees all internally allocated memory. Do not attempt to use the object after calling this method.
References cgul_random_mt32__delete().
§ allocate_seed_array()
static void cgul_random_mt32_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] | v | uninitialized array of 32-bit seed values |
[out] | v_count | count of the number of 32-bit values in v |
References cgul_random_mt32__allocate_seed_array().
§ next()
virtual cgul_uint32_t cgul_random_mt32_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^19937 - 1).
- Returns
- next element in the random number sequence
- See also
- next_in_range()
-
next_in_unit()
References cgul_random_mt32__next().
§ next_in_range()
virtual cgul_uint32_t cgul_random_mt32_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_max | exclusive limit on the maximum value returned |
- Returns
- next element in the random number sequence
References cgul_random_mt32__next_in_range().
§ next_in_unit()
virtual double cgul_random_mt32_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_mt32__next_in_unit().
§ get_obj()
Get the underlying cgul_random_mt32
object.
- Returns
- underlying object
§ take_obj()
Take the underlying cgul_random_mt32
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_mt32__delete()
.
- Returns
- underlying object
§ set_obj()
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
-
References cgul_random_mt32__delete(), and cgul_random_mt32_cxx().
The documentation for this class was generated from the following file: