FastLED 3.7.8
Loading...
Searching...
No Matches
random8.h
Go to the documentation of this file.
1#ifndef __INC_LIB8TION_RANDOM_H
2#define __INC_LIB8TION_RANDOM_H
3
7
10
21
23#define FASTLED_RAND16_2053 ((uint16_t)(2053))
25#define FASTLED_RAND16_13849 ((uint16_t)(13849))
26
27#if defined(LIB8_ATTINY)
29#define APPLY_FASTLED_RAND16_2053(x) (x << 11) + (x << 2) + x
30#else
32#define APPLY_FASTLED_RAND16_2053(x) (x * FASTLED_RAND16_2053)
33#endif
34
36extern uint16_t rand16seed; // = RAND16_SEED;
37
42 // return the sum of the high and low bytes, for better
43 // mixing and non-sequential correlation
44 return (uint8_t)(((uint8_t)(rand16seed & 0xFF)) +
45 ((uint8_t)(rand16seed >> 8)));
46}
47
54
57LIB8STATIC uint8_t random8(uint8_t lim) {
58 uint8_t r = random8();
59 r = (r * lim) >> 8;
60 return r;
61}
62
66LIB8STATIC uint8_t random8(uint8_t min, uint8_t lim) {
67 uint8_t delta = lim - min;
68 uint8_t r = random8(delta) + min;
69 return r;
70}
71
74LIB8STATIC uint16_t random16(uint16_t lim) {
75 uint16_t r = random16();
76 uint32_t p = (uint32_t)lim * (uint32_t)r;
77 r = p >> 16;
78 return r;
79}
80
84LIB8STATIC uint16_t random16(uint16_t min, uint16_t lim) {
85 uint16_t delta = lim - min;
86 uint16_t r = random16(delta) + min;
87 return r;
88}
89
91LIB8STATIC void random16_set_seed(uint16_t seed) { rand16seed = seed; }
92
95
97LIB8STATIC void random16_add_entropy(uint16_t entropy) {
98 rand16seed += entropy;
99}
100
103
104#endif
LIB8STATIC void random16_add_entropy(uint16_t entropy)
Add entropy into the random number generator.
Definition random8.h:97
LIB8STATIC uint16_t random16()
Generate a 16-bit random number.
Definition random8.h:50
LIB8STATIC uint8_t random8()
Generate an 8-bit random number.
Definition random8.h:40
uint16_t rand16seed
Seed for the random number generator functions.
Definition lib8tion.cpp:15
LIB8STATIC uint16_t random16_get_seed()
Get the current seed value for the random number generator.
Definition random8.h:94
#define APPLY_FASTLED_RAND16_2053(x)
Multiplies a value by the pseudo-random multiplier.
Definition random8.h:32
#define FASTLED_RAND16_13849
Increment value for pseudo-random number generation.
Definition random8.h:25
LIB8STATIC void random16_set_seed(uint16_t seed)
Set the 16-bit seed used for the random number generator.
Definition random8.h:91
#define LIB8STATIC
Define a LIB8TION member function as static inline with an "unused" attribute.
Definition lib8tion.h:22