Browse Source

add random function

tags/1.0.0
Chris Cromer 11 months ago
parent
commit
a71cae2d22
Signed by: Chris Cromer <chris@cromer.cl> GPG Key ID: 39CC813FF3C8708A
3 changed files with 17 additions and 1 deletions
  1. 1
    1
      Makefile
  2. 4
    0
      src/include/random.h
  3. 12
    0
      src/random.c

+ 1
- 1
Makefile 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
- 0
src/include/random.h View File

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

+ 12
- 0
src/random.c 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;
}

Loading…
Cancel
Save