#include "prng.h"
#include "LPC17xx.h"
Go to the source code of this file.
|
void | PRNG_Set (u32 seed) |
| Initializes the PRNG by seeding it with the given seed. Use PRNG_USE_AUTO_SEED to seed it automatically using an HW entropy source.
|
|
void | PRNG_Release (void) |
| Releases the HW entropy sources used to seed the PRNG.
|
|
u32 | PRNG_Next (void) |
| Generates the next pseudo-random number.
|
|
u32 | PRNG_Range (u32 min, u32 max) |
| Generates a pseudo-random number in the given range, inclusive.
|
|
◆ PRNG_Next()
Generates the next pseudo-random number.
- Returns
- The PRN
Definition at line 38 of file prng.c.
◆ PRNG_Range()
Generates a pseudo-random number in the given range, inclusive.
- Parameters
-
min | Lower bound |
max | Upper bound |
- Returns
- The PRN
Definition at line 49 of file prng.c.
50{
51 if (min > max)
52 {
53
55 min = max;
56 max = temp;
57 }
58
59 u32 range = max - min + 1;
61}
u32 PRNG_Next(void)
Generates the next pseudo-random number.
◆ PRNG_Release()
void PRNG_Release |
( |
void |
| ) |
|
Releases the HW entropy sources used to seed the PRNG.
Definition at line 29 of file prng.c.
30{
31
32 SysTick->CTRL = 0;
34}
◆ PRNG_Set()
void PRNG_Set |
( |
u32 |
seed | ) |
|
Initializes the PRNG by seeding it with the given seed. Use PRNG_USE_AUTO_SEED to seed it automatically using an HW entropy source.
- Parameters
-
Definition at line 7 of file prng.c.
8{
10 {
11
12 if (!(SysTick->CTRL & SysTick_CTRL_ENABLE_Msk))
13 {
14 SysTick->LOAD = 0xFFFFFF;
15 SysTick->VAL = 0;
16 SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
17 }
18
19
20 prng_state = SysTick->VAL ^ (SysTick->VAL << 16) ^ (SysTick->LOAD);
21 return;
22 }
23
24
26}
@ PRNG_USE_AUTO_SEED
PRNG automatically seeds itself using an hardware entropy source.
◆ prng_state
Definition at line 5 of file prng.c.