UoS³ Flight Computer Firmware
 All Data Structures Files Functions Groups Pages
random.c
Go to the documentation of this file.
1 
11 #include "board.h"
12 
13 #include "../random.h"
14 
15 #include <stdlib.h>
16 #include <stdbool.h>
17 
18 static bool rng_seeded = false;
19 
20 uint32_t Random(uint32_t max)
21 {
22  uint32_t prev, out;
23 
24  if(!rng_seeded)
25  {
26  srand(4); // TODO: Use a better source
27  rng_seeded = true;
28  }
29 
30  out = (uint32_t)rand();
31  prev = out;
32 
33  while(prev == out)
34  {
35  out = (uint32_t)rand();
36  }
37 
38  return (uint32_t)((float)out * ((float)max / (float)RAND_MAX));
39 }
40 
uint32_t Random(uint32_t max)
Definition: random.c:21