FastLED 3.7.8
Loading...
Searching...
No Matches
Fast Random Number Generators

Detailed Description

Fast 8-bit and 16-bit unsigned random number generators.

Significantly faster than Arduino random(), but also somewhat less random. You can add entropy.

Pseudo-random number generation follows the form:

X(n+1) = (2053 * X(n)) + 13849)
uint16_t rand16seed
 Seed for the random number generator functions.
 
LIB8STATIC uint8_t random8 ()
 Generate an 8-bit random number.
 
LIB8STATIC uint16_t random16 ()
 Generate a 16-bit random number.
 
LIB8STATIC uint8_t random8 (uint8_t lim)
 Generate an 8-bit random number between 0 and lim.
 
LIB8STATIC uint8_t random8 (uint8_t min, uint8_t lim)
 Generate an 8-bit random number in the given range.
 
LIB8STATIC uint16_t random16 (uint16_t lim)
 Generate an 16-bit random number between 0 and lim.
 
LIB8STATIC uint16_t random16 (uint16_t min, uint16_t lim)
 Generate an 16-bit random number in the given range.
 
LIB8STATIC void random16_set_seed (uint16_t seed)
 Set the 16-bit seed used for the random number generator.
 
LIB8STATIC uint16_t random16_get_seed ()
 Get the current seed value for the random number generator.
 
LIB8STATIC void random16_add_entropy (uint16_t entropy)
 Add entropy into the random number generator.
 
#define FASTLED_RAND16_2053   ((uint16_t)(2053))
 Multiplier value for pseudo-random number generation.
 
#define FASTLED_RAND16_13849   ((uint16_t)(13849))
 Increment value for pseudo-random number generation.
 
#define APPLY_FASTLED_RAND16_2053(x)   (x * FASTLED_RAND16_2053)
 Multiplies a value by the pseudo-random multiplier.
 

Macro Definition Documentation

◆ APPLY_FASTLED_RAND16_2053

#define APPLY_FASTLED_RAND16_2053 ( x)    (x * FASTLED_RAND16_2053)

Multiplies a value by the pseudo-random multiplier.

Definition at line 32 of file random8.h.

◆ FASTLED_RAND16_13849

#define FASTLED_RAND16_13849   ((uint16_t)(13849))

Increment value for pseudo-random number generation.

Definition at line 25 of file random8.h.

◆ FASTLED_RAND16_2053

#define FASTLED_RAND16_2053   ((uint16_t)(2053))

Multiplier value for pseudo-random number generation.

Definition at line 23 of file random8.h.

Function Documentation

◆ random16() [1/3]

LIB8STATIC uint16_t random16 ( )

Generate a 16-bit random number.

Returns
random 16-bit number, in the range 0-65535
Examples
DemoReel100.ino, Noise.ino, NoisePlayground.ino, NoisePlusPalette.ino, and SmartMatrix.ino.

Definition at line 50 of file random8.h.

◆ random16() [2/3]

LIB8STATIC uint16_t random16 ( uint16_t lim)

Generate an 16-bit random number between 0 and lim.

Parameters
limthe upper bound for the result, exclusive

Definition at line 74 of file random8.h.

◆ random16() [3/3]

LIB8STATIC uint16_t random16 ( uint16_t min,
uint16_t lim )

Generate an 16-bit random number in the given range.

Parameters
minthe lower bound for the random number, inclusive
limthe upper bound for the random number, exclusive

Definition at line 84 of file random8.h.

◆ random16_add_entropy()

LIB8STATIC void random16_add_entropy ( uint16_t entropy)

Add entropy into the random number generator.

Examples
Fire2012WithPalette.ino, and NoisePlayground.ino.

Definition at line 97 of file random8.h.

◆ random16_get_seed()

LIB8STATIC uint16_t random16_get_seed ( )

Get the current seed value for the random number generator.

Definition at line 94 of file random8.h.

◆ random16_set_seed()

LIB8STATIC void random16_set_seed ( uint16_t seed)

Set the 16-bit seed used for the random number generator.

Examples
NoisePlayground.ino.

Definition at line 91 of file random8.h.

◆ random8() [1/3]

LIB8STATIC uint8_t random8 ( )

Generate an 8-bit random number.

Returns
random 8-bit number, in the range 0-255
Examples
ColorPalette.ino, DemoReel100.ino, Fire2012.ino, Fire2012WithPalette.ino, and NoisePlusPalette.ino.

Definition at line 40 of file random8.h.

◆ random8() [2/3]

LIB8STATIC uint8_t random8 ( uint8_t lim)

Generate an 8-bit random number between 0 and lim.

Parameters
limthe upper bound for the result, exclusive

Definition at line 57 of file random8.h.

◆ random8() [3/3]

LIB8STATIC uint8_t random8 ( uint8_t min,
uint8_t lim )

Generate an 8-bit random number in the given range.

Parameters
minthe lower bound for the random number, inclusive
limthe upper bound for the random number, exclusive

Definition at line 66 of file random8.h.

Variable Documentation

◆ rand16seed

uint16_t rand16seed
extern

Seed for the random number generator functions.

Definition at line 15 of file lib8tion.cpp.