FastLED 3.9.15
Loading...
Searching...
No Matches
random8.h
Go to the documentation of this file.
1#pragma once
2
3#ifndef __INC_LIB8TION_RANDOM_H
4#define __INC_LIB8TION_RANDOM_H
5
6#include <stdint.h>
7
9
13
16
27
29#define FASTLED_RAND16_2053 ((uint16_t)(2053))
31#define FASTLED_RAND16_13849 ((uint16_t)(13849))
32
33#if defined(LIB8_ATTINY)
35#define APPLY_FASTLED_RAND16_2053(x) (x << 11) + (x << 2) + x
36#else
38#define APPLY_FASTLED_RAND16_2053(x) (x * FASTLED_RAND16_2053)
39#endif
40
42extern uint16_t rand16seed; // = RAND16_SEED;
43
48 // return the sum of the high and low bytes, for better
49 // mixing and non-sequential correlation
50 return (uint8_t)(((uint8_t)(rand16seed & 0xFF)) +
51 ((uint8_t)(rand16seed >> 8)));
52}
53
60
63LIB8STATIC uint8_t random8(uint8_t lim) {
64 uint8_t r = random8();
65 r = (r * lim) >> 8;
66 return r;
67}
68
72LIB8STATIC uint8_t random8(uint8_t min, uint8_t lim) {
73 uint8_t delta = lim - min;
74 uint8_t r = random8(delta) + min;
75 return r;
76}
77
80LIB8STATIC uint16_t random16(uint16_t lim) {
81 uint16_t r = random16();
82 uint32_t p = (uint32_t)lim * (uint32_t)r;
83 r = p >> 16;
84 return r;
85}
86
90LIB8STATIC uint16_t random16(uint16_t min, uint16_t lim) {
91 uint16_t delta = lim - min;
92 uint16_t r = random16(delta) + min;
93 return r;
94}
95
97LIB8STATIC void random16_set_seed(uint16_t seed) { rand16seed = seed; }
98
101
103LIB8STATIC void random16_add_entropy(uint16_t entropy) {
104 rand16seed += entropy;
105}
106
109
110#endif
LIB8STATIC void random16_add_entropy(uint16_t entropy)
Add entropy into the random number generator.
Definition random8.h:103
LIB8STATIC uint16_t random16()
Generate a 16-bit random number.
Definition random8.h:56
LIB8STATIC uint8_t random8()
Generate an 8-bit random number.
Definition random8.h:46
uint16_t rand16seed
Seed for the random number generator functions.
Definition lib8tion.cpp:17
LIB8STATIC uint16_t random16_get_seed()
Get the current seed value for the random number generator.
Definition random8.h:100
#define APPLY_FASTLED_RAND16_2053(x)
Multiplies a value by the pseudo-random multiplier.
Definition random8.h:38
#define FASTLED_RAND16_13849
Increment value for pseudo-random number generation.
Definition random8.h:31
LIB8STATIC void random16_set_seed(uint16_t seed)
Set the 16-bit seed used for the random number generator.
Definition random8.h:97
#define LIB8STATIC
Define a LIB8TION member function as static inline with an "unused" attribute.
Definition lib8static.h:10
Defines static inlining macros for lib8tion functions.
static FASTLED_NAMESPACE_BEGIN uint8_t const p[]
Definition noise.cpp:30