-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomizer.c
30 lines (24 loc) · 1009 Bytes
/
randomizer.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
/*----------------------------------------------------------------------------
Copyright (c) 2013 Gauthier Fleutot Östervall
----------------------------------------------------------------------------*/
#include "randomizer.h"
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
//******************************************************************************
// Module variables
//******************************************************************************
static bool randomizer_seeded = false;
//******************************************************************************
// Function definitions
//******************************************************************************
int random_get(const int limit)
{
if (!randomizer_seeded) {
srand(time(NULL));
randomizer_seeded = true;
}
// This does not give real uniformity, but since random returns long int and
// limit is not expect to be very large, it is enough.
return (int) (rand() % limit);
}