add random function
This commit is contained in:
parent
2a82656482
commit
a71cae2d22
2
Makefile
2
Makefile
@ -2,7 +2,7 @@ CC=gcc
|
|||||||
CFLAGS=-Wall -Werror
|
CFLAGS=-Wall -Werror
|
||||||
CPPFLAGS+=-Isrc/include
|
CPPFLAGS+=-Isrc/include
|
||||||
#LDFLAGS=-lm
|
#LDFLAGS=-lm
|
||||||
SRC=src/sort.c
|
SRC=src/sort.c src/random.c
|
||||||
OBJ=$(SRC:.c=.o)
|
OBJ=$(SRC:.c=.o)
|
||||||
|
|
||||||
all: sort informe
|
all: sort informe
|
||||||
|
4
src/include/random.h
Normal file
4
src/include/random.h
Normal 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
12
src/random.c
Normal 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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user