-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.c
57 lines (49 loc) · 1.2 KB
/
helper.c
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdlib.h>
#include "helper.h"
int queue_head = 0;
void enqueue(struct Sensor arr[], int length, struct Sensor element)
{
if (queue_head == length) {
for (int i = 1; i < length; ++i) {
arr[i-1] = arr[i];
}
queue_head--;
}
arr[queue_head] = element;
queue_head++;
}
/**
* Generate a random floating point number from min to max
* @param min
* @param max
* @return
*/
float float_rand(float min, float max)
{
float range = (max - min);
float div = RAND_MAX / range;
return min + (rand() / div);
}
/**
* Generate a random floating point number from min to max
* @param min
* @param max
* @return
*/
float float_rand_seed(float min, float max, int seed)
{
float range = (max - min);
float div = RAND_MAX / range;
float f = 0;
for (int i = 0; i <= seed; i++) {
f = min + (rand() / div);
}
return f;
}
void printReading(struct Sensor* reading)
{
printf("%d\t| %d\t| %d\t| %d\t| %d\t| %d\t| %.2f\t| %.2f\t| %.2f\t| %.2f\n",
reading->year, reading->month, reading->day, reading->hour,
reading->minute, reading->second, reading->lat, reading->lon,
reading->mag, reading->depth);
}