dtrandomizer
Facade provides a uniform interface for producing sequences of random integers.
Please refer to dtvtable for more information on vtable dispatching.
You can use this facade to implement various randomization strategies, such as uniform distribution, Gaussian distribution, or custom algorithms. The particular algorithm is selected at runtime based on the model number associated with the randomizer instance, allowing configurable behavior without changing the call sites.
Mini-guide
- For a class to implement this facade, it must register a
dtrandomizer_vt_tvtable for its model number and implement all the functions below. - To call the facade functions, pass the handle to the function cast as
dtrandomizer_handle.
Example
#include <dtcore/dtrandomizer.h>
#include <dtcore/dtrandomizer_uniform.h>
dtrandomizer_handle h = NULL;
// crate a concrete uniform randomizer instance as handle
dtrandomizer_uniform_create((dtrandomizer_uniform_t*)&h);
// access the randomizer via the dispatch API
int32_t v = 0;
dtrandomizer_next(h, &v);
dtrandomizer_dispose(h);
Data structures
dtrandomizer_handle
Defines the opaque handle type used by the dispatch API.
dtrandomizer_vt_t
Provides the dispatch table for the randomizer interface.
Members :
dtrandomizer_next_fn nextProduces the next value for the implementation.
dtrandomizer_reset_fn resetResets the implementation state.
dtrandomizer_dispose_fn disposeDisposes the implementation instance.
Macros
DTRANDOMIZER_COMMON_MEMBERS
Defines the common leading members required by implementations.
DTRANDOMIZER_DECLARE_API
DTRANDOMIZER_DECLARE_API(NAME)
Declares the implementation-side randomizer interface functions for a concrete type.
DTRANDOMIZER_INIT_VTABLE
DTRANDOMIZER_INIT_VTABLE(NAME)
Defines a static dtrandomizer_vt_t that binds the implementation interface functions.
Functions
dtrandomizer_dispose
Disposes a randomizer instance by dispatching to its registered vtable.
Params :
dtrandomizer_handle handleRandomizer instance handle used for dispatch.
Return: void No return value.
dtrandomizer_next
Produces the next randomizer value by dispatching to its registered vtable.
Params :
dtrandomizer_handle handleRandomizer instance handle used for dispatch.
int32_t* valueOutput location that receives the produced value.
Return: dterr_t* Error pointer, or NULL on success.
dtrandomizer_reset
Resets a randomizer instance by dispatching to its registered vtable.
Params :
dtrandomizer_handle handleRandomizer instance handle used for dispatch.
Return: dterr_t* Error pointer, or NULL on success.