-
Notifications
You must be signed in to change notification settings - Fork 0
/
random.c
46 lines (41 loc) · 1.38 KB
/
random.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* random.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ptao <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/01/30 23:57:21 by ptao #+# #+# */
/* Updated: 2016/01/31 19:57:49 by ptao ### ########.fr */
/* */
/* ************************************************************************** */
#include "game.h"
static int generate_random_pos(int low, int high)
{
srand(time(NULL));
return ((rand() % (high - low + 1)) + low);
}
static int generate_random_val(void)
{
srand(time(NULL));
return (2 * ((rand() % 2) + 1));
}
void generate_random(int len, int tab[len][len])
{
int gen;
int i;
int j;
int pos;
gen = 1;
while (gen)
{
pos = generate_random_pos(0, len * len - 1);
i = pos / len;
j = pos % len;
if (tab[i][j] == 0)
{
tab[i][j] = generate_random_val();
gen = 0;
}
}
}