add random function

This commit is contained in:
Chris Cromer 2018-11-07 14:46:42 -03:00
parent 2a82656482
commit a71cae2d22
Signed by: cromer
GPG Key ID: 39CC813FF3C8708A
3 changed files with 17 additions and 1 deletions

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;
}