feat(lv_math): add lv_rand_set_seed api (#5013)

This commit is contained in:
Benign X
2023-12-14 21:22:54 +08:00
committed by GitHub
parent cad4a4529c
commit 492a474f5f
3 changed files with 12 additions and 1 deletions

View File

@@ -87,7 +87,7 @@ static inline void lv_global_init(lv_global_t * global)
global->style_last_custom_prop_id = (uint32_t)_LV_STYLE_LAST_BUILT_IN_PROP;
global->area_trans_cache.angle_prev = INT32_MIN;
global->event_last_register_id = _LV_EVENT_LAST;
global->math_rand_seed = 0x1234ABCD;
lv_rand_set_seed(0x1234ABCD);
#if defined(LV_DRAW_SW_SHADOW_CACHE_SIZE) && LV_DRAW_SW_SHADOW_CACHE_SIZE > 0
global->sw_shadow_cache.cache_size = -1;

View File

@@ -333,6 +333,11 @@ int32_t lv_map(int32_t x, int32_t min_in, int32_t max_in, int32_t min_out, int32
return ((x - min_in) * delta_out) / delta_in + min_out;
}
void lv_rand_set_seed(uint32_t seed)
{
rand_seed = seed;
}
uint32_t lv_rand(uint32_t min, uint32_t max)
{
/*Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs"*/

View File

@@ -125,6 +125,12 @@ int64_t lv_pow(int64_t base, int8_t exp);
*/
int32_t lv_map(int32_t x, int32_t min_in, int32_t max_in, int32_t min_out, int32_t max_out);
/**
* Set the seed of the pseudo random number generator
* @param seed a number to initialize the random generator
*/
void lv_rand_set_seed(uint32_t seed);
/**
* Get a pseudo random number in the given range
* @param min the minimum value