FastLED 3.9.15
Loading...
Searching...
No Matches
fl::fl_random Class Reference

Detailed Description

A random number generator class that wraps FastLED's random functions.

This class provides a standard C++ random generator interface that can be used with algorithms like fl::shuffle. Each instance maintains its own seed state independent of other instances and the global FastLED random state.

fl::vector<int> vec = {1, 2, 3, 4, 5};
fl::shuffle(vec.begin(), vec.end(), rng);
iterator begin()
Definition vector.h:584
iterator end()
Definition vector.h:590
A random number generator class that wraps FastLED's random functions.
Definition random.h:20
void shuffle(Iterator first, Iterator last, RandomGenerator &g)
Definition algorithm.h:527
HeapVector< T, Allocator > vector
Definition vector.h:1214

Definition at line 20 of file random.h.

#include <random.h>

Public Types

typedef u32 result_type
 The result type for this random generator (32-bit unsigned integer)
 

Public Member Functions

 fl_random ()
 Default constructor - uses current global random seed.
 
 fl_random (u16 seed)
 Constructor with explicit seed.
 
void add_entropy (u16 entropy)
 Add entropy to this random number generator instance.
 
u16 get_seed () const
 Get the current seed value for this instance.
 
result_type operator() ()
 Generate a random number.
 
result_type operator() (result_type min, result_type max)
 Generate a random number in the range [min, max)
 
result_type operator() (result_type n)
 Generate a random number in the range [0, n)
 
u16 random16 ()
 Generate a 16-bit random number.
 
u16 random16 (u16 min, u16 max)
 Generate a 16-bit random number in the range [min, max)
 
u16 random16 (u16 n)
 Generate a 16-bit random number in the range [0, n)
 
u8 random8 ()
 Generate an 8-bit random number.
 
u8 random8 (u8 min, u8 max)
 Generate an 8-bit random number in the range [min, max)
 
u8 random8 (u8 n)
 Generate an 8-bit random number in the range [0, n)
 
void set_seed (u16 seed)
 Set the seed for this random number generator instance.
 

Static Public Member Functions

static constexpr result_type maximum ()
 Get the maximum value this generator can produce.
 
static constexpr result_type minimum ()
 Get the minimum value this generator can produce.
 

Private Member Functions

u16 next_random16 ()
 Generate next 16-bit random number using this instance's seed.
 
u32 next_random32 ()
 Generate next 32-bit random number using this instance's seed.
 

Private Attributes

u16 seed_
 The current seed state for this instance.
 

The documentation for this class was generated from the following file: