dtrandomizer_browngrav
Brownian motion with attraction toward a fixed point.
This group of functions provides a stateful random sequence generator for integer-valued signals. Use it for simulations and effect generation that require bounded but wandering behavior. It is designed to combine random noise with a restoring force toward a target value.
This class implements these facades:
- dtrandomizer - for generating random sequences.
- dtpackable - for serializing and deserializing the configuration and state.
- dtobject - for basic object operations like creation, copying, and disposal.
Mini-guide
- Create, initialize and configure the instance before use.
- Configure behavior by supplying attraction and noise parameters through the config structure.
- Generate successive values by calling the next function with a persistent instance.
- Reset the internal state when changing configuration or reseeding the generator.
- Use the facade interfaces for polymorphic handling and serialization.
Example
dtrandomizer_browngrav_t* r = NULL;
dtrandomizer_handle h = NULL;
dtrandomizer_browngrav_config_t cfg;
int32_t value;
dtrandomizer_browngrav_create(&r);
cfg.attraction_point = 0;
cfg.attraction_strength = 5;
cfg.noise_intensity = 10;
cfg.seed = 0;
dtrandomizer_browngrav_config(r, &cfg);
// use the randomizer facade handle thereafter
h = (dtrandomizer_handle)r;
dtrandomizer_next(h, &value);
// use the object facade to get a string representation
char buffer[128];
dtobject_to_string((dtobject_handle_t)h, buffer, sizeof(buffer));
dtobject_dispose((dtobject_handle_t)h);
Data structures
dtrandomizer_browngrav_config_t
Defines configuration parameters that control the randomizer behavior.
Members:
int32_t attraction_pointTarget value toward which the sequence is pulled.
int32_t attraction_strengthStrength of the restoring force toward the target.
int32_t noise_intensityMaximum magnitude of random deviation per step.
int32_t seedSeed value used to initialize the random number generator.
Functions
dtrandomizer_browngrav_create
Create a new instance. This implies dtrandomizer_browngrav_init().
After create, configuration must be applied before use.
Params:
dtrandomizer_browngrav_t** selfOutput pointer that receives the allocated instance.
Return: dterr_t* Error object on failure or NULL on success.
dtrandomizer_browngrav_config
Applies a new configuration and resets internal state.
Params:
dtrandomizer_browngrav_t* selfInstance to configure.
dtrandomizer_browngrav_config_t* configurationConfiguration values to apply.
Return: dterr_t* Error object on failure or NULL on success.
dtrandomizer_browngrav_init
Initializes an instance to a default state.
Params:
dtrandomizer_browngrav_t* selfInstance to initialize.
Return: dterr_t* Error object on failure or NULL on success.