Pseudo Random Number Generator (PRNG)  
More...
Pseudo Random Number Generator (PRNG) 
Various implementations of a PRNG are available:
- Tiny Mersenne Twister (default)
 
- Mersenne Twister
 
- Simple Park-Miller PRNG
 
- Musl C PRNG
 
- Fortuna (CS)PRNG
 
- Hardware Random Number Generator (non-seedable) HWRNG differ in how they generate random numbers and may not use a PRNG internally. Refer to the manual of your MCU for details.
 
By default, the auto_init_random module is enabled, which initializes the PRNG on startup. However, there is no lower limit on the entropy provided at that time. Unless the periph_hwrng module is used, entropy may be as little as zero (the constant may even be the same across devices). 
 | 
| file   | random.h | 
|   | Common interface to the software PRNG. 
  | 
|   | 
 | 
| 
#define  | RANDOM_SEED_DEFAULT   (1) | 
|   | Seed selected when all tries to collect seeds from a random source failed. 
  | 
|   | 
| 
#define  | PRNG_FLOAT   (0) | 
|   | Enables support for floating point random number generation. 
  | 
|   | 
 | 
| void  | random_init (uint32_t s) | 
|   | initializes PRNG with a seed  More...
  | 
|   | 
| void  | random_init_by_array (uint32_t init_key[], int key_length) | 
|   | initialize by an array with array-length init_key is the array for initializing keys key_length is its length slight change for C++, 2004/2/26  More...
  | 
|   | 
| uint32_t  | random_uint32 (void) | 
|   | generates a random number on [0,0xffffffff]-interval  More...
  | 
|   | 
| 
void  | random_bytes (void *buf, size_t size) | 
|   | writes random bytes in the [0,0xff]-interval to memory 
  | 
|   | 
| uint32_t  | random_uint32_range (uint32_t a, uint32_t b) | 
|   | generates a random number r with a <= r < b.  More...
  | 
|   | 
| double  | random_real (void) | 
|   | generates a random number on [0,1)-real-interval  More...
  | 
|   | 
| double  | random_real_inclusive (void) | 
|   | generates a random number on [0,1]-real-interval  More...
  | 
|   | 
| double  | random_real_exclusive (void) | 
|   | generates a random number on (0,1)-real-interval  More...
  | 
|   | 
| double  | random_res53 (void) | 
|   | generates a random number on [0,1) with 53-bit resolution  More...
  | 
|   | 
◆ random_init()
      
        
          | void random_init  | 
          ( | 
          uint32_t  | 
          s | ) | 
           | 
        
      
 
initializes PRNG with a seed 
Users only need to call this if the auto_init_random module is disabled, or provides insufficient quality entropy.
- Warning
 - Currently, the random module uses a global state => multiple calls to random_init will reset the existing state of the PRNG.
 
- Parameters
 - 
  
  
 
 
 
◆ random_init_by_array()
      
        
          | void random_init_by_array  | 
          ( | 
          uint32_t  | 
          init_key[],  | 
        
        
           | 
           | 
          int  | 
          key_length  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
initialize by an array with array-length init_key is the array for initializing keys key_length is its length slight change for C++, 2004/2/26 
- Parameters
 - 
  
    | init_key | array of keys (seeds) to initialize the PRNG  | 
    | key_length | number of elements in init_key  | 
  
   
 
 
◆ random_real()
      
        
          | double random_real  | 
          ( | 
          void  | 
           | ) | 
           | 
        
      
 
generates a random number on [0,1)-real-interval 
- Returns
 - a random number on [0,1)-real-interval 
 
 
 
◆ random_real_exclusive()
      
        
          | double random_real_exclusive  | 
          ( | 
          void  | 
           | ) | 
           | 
        
      
 
generates a random number on (0,1)-real-interval 
- Returns
 - a random number on (0,1)-real-interval 
 
 
 
◆ random_real_inclusive()
      
        
          | double random_real_inclusive  | 
          ( | 
          void  | 
           | ) | 
           | 
        
      
 
generates a random number on [0,1]-real-interval 
- Returns
 - a random number on [0,1]-real-interval 
 
 
 
◆ random_res53()
      
        
          | double random_res53  | 
          ( | 
          void  | 
           | ) | 
           | 
        
      
 
generates a random number on [0,1) with 53-bit resolution 
- Returns
 - a random number on [0,1) with 53-bit resolution 
 
 
 
◆ random_uint32()
      
        
          | uint32_t random_uint32  | 
          ( | 
          void  | 
           | ) | 
           | 
        
      
 
generates a random number on [0,0xffffffff]-interval 
- Returns
 - a random number on [0,0xffffffff]-interval 
 
 
 
◆ random_uint32_range()
      
        
          | uint32_t random_uint32_range  | 
          ( | 
          uint32_t  | 
          a,  | 
        
        
           | 
           | 
          uint32_t  | 
          b  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
generates a random number r with a <= r < b. 
- Parameters
 - 
  
    | [in] | a | minimum for random number  | 
    | [in] | b | upper bound for random number | 
  
   
- Precondition
 - a < b
 
- Returns
 - a random number on [a,b)-interval