C++ bindings for cgul_random_xorshift32
More...
#include <cgul_random_xorshift32_cxx.h>
Public Member Functions | |
cgul_random_xorshift32_cxx () | |
cgul_random_xorshift32_cxx (cgul_uint32_t seed) | |
cgul_random_xorshift32_cxx (cgul_uint32_t *seeds) | |
cgul_random_xorshift32_cxx (cgul_random_xorshift32_t rhs) | |
virtual | ~cgul_random_xorshift32_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_xorshift32_t | get_obj () const |
virtual cgul_random_xorshift32_t | take_obj () |
virtual void | set_obj (cgul_random_xorshift32_t rhs) |
Static Public Member Functions | |
static void | allocate_seed_array (cgul_uint32_t **v, unsigned int *v_count) |
This class provides the C++ bindings for cgul_random_xorshift32
. 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.
|
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_xorshift32__new().
Referenced by set_obj().
|
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.
[in] | seed | seed value |
References cgul_random_xorshift32__new_from_seed().
|
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.
[in] | seeds | array of 32-bit values used to seed the PRNG |
References cgul_random_xorshift32__new_from_seed_array().
|
inline |
Create a new cgul_random_xorshift32_cxx
object by wrapping an existing cgul_random_xorshift32
object.
[in] | rhs | right-hand side |
|
inlinevirtual |
This method frees all internally allocated memory. Do not attempt to use the object after calling this method.
References cgul_random_xorshift32__delete().
|
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.
[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_xorshift32__allocate_seed_array().
|
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^4096 - 1).
References cgul_random_xorshift32__next().
|
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.
[in] | range_max | exclusive limit on the maximum value returned |
References cgul_random_xorshift32__next_in_range().
|
inlinevirtual |
Return the next element in the pseudo-random number sequence as type double
on the range [0 - 1).
References cgul_random_xorshift32__next_in_unit().
|
inlinevirtual |
Get the underlying cgul_random_xorshift32
object.
|
inlinevirtual |
Take the underlying cgul_random_xorshift32
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_xorshift32__delete()
.
|
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.
[in] | rhs | right-hand side |
References cgul_random_xorshift32__delete(), and cgul_random_xorshift32_cxx().