-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.c
37 lines (33 loc) · 671 Bytes
/
util.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
#include <jo/jo.h>
#include "util.h"
// shuffles an array of integers
void shuffleArray(unsigned int* array, unsigned int size)
{
unsigned int i = 0;
for (i = 0; i < size - 1; i++)
{
unsigned int j = i + jo_random(0xFFFF) / (0xFFFF / (size - i) + 1);
int t = array[j];
array[j] = array[i];
array[i] = t;
}
}
// bound integer value between min - max-1;
void sanitizeValue(int* value, int min, int max)
{
if(*value < min)
{
*value = max - 1;
}
else if(*value >= max)
{
*value = min;
}
}
void errorPrint(char* message)
{
while(1)
{
jo_printf(0, 0, message);
}
}