Add random functionality #4

Merged
cromer merged 3 commits from random into master 2018-11-07 14:56:23 -03:00
3 changed files with 17 additions and 1 deletions
Showing only changes of commit a71cae2d22 - Show all commits

View File

@ -2,7 +2,7 @@ CC=gcc
CFLAGS=-Wall -Werror
CPPFLAGS+=-Isrc/include
#LDFLAGS=-lm
SRC=src/sort.c
SRC=src/sort.c src/random.c
OBJ=$(SRC:.c=.o)
all: sort informe

4
src/include/random.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef _SORT_RANDOM
#define _SORT_RANDOM
int gen_rand(int min, int max);
#endif

12
src/random.c Normal file
View File

@ -0,0 +1,12 @@
#include <stdlib.h>
#include <time.h>
static int sort_rand_initialized = 0;
int gen_rand(int min, int max) {
if (sort_rand_initialized == 0) {
srand((unsigned int) time(NULL));
sort_rand_initialized = 1;
}
return rand() % (max + 1 - min) + min;
}