-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom.h
More file actions
39 lines (34 loc) · 1.15 KB
/
Copy pathrandom.h
File metadata and controls
39 lines (34 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Random number generator;
// Linear congruential generator
// from Numerical Recipes by Press et al.
// Jonathan Valvano
// How to use
// 1) call Random_Init once with a seed
// Random_Init(1);
// or Random_Init(NVIC_CURRENT_R);
// 2) call Random over and over to get a new random number
// n = Random(); // 8 bit number
// m = (Random32()>>24)%60; // a number from 0 to 59
#include <stdint.h>
// initialize random number generator
// the generator cycles through all 32-bit values, seed is the place to start
// input: any 32-bit number
// output: none
void Random_Init(uint32_t seed);
//------------Random32------------
// Return 32-bit random number
// Linear congruential generator
// from Numerical Recipes by Press et al.
// Input: none
// Output: random number
// warning: the bottom bits are not that randome
// bit 0 oscillates 0,1,0,1,...
// bit n cycles through a sequence of length n+1
uint32_t Random32(void);
//------------Random------------
// Return random number, 0 to 255
// Linear congruential generator
// from Numerical Recipes by Press et al.
// Input: none
// Output: random number
uint8_t Random (void);