collab/PineapplePad

git clone https://git.julia.blue/collab/PineapplePad

Joseph RyanAdd starter filesaa6d022

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