From a71cae2d2283c8c59fc851528271213dcc777f64 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Wed, 7 Nov 2018 14:46:42 -0300 Subject: [PATCH 1/3] add random function --- Makefile | 2 +- src/include/random.h | 4 ++++ src/random.c | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/include/random.h create mode 100644 src/random.c diff --git a/Makefile b/Makefile index 9715102..9f80acf 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/include/random.h b/src/include/random.h new file mode 100644 index 0000000..c2eabd0 --- /dev/null +++ b/src/include/random.h @@ -0,0 +1,4 @@ +#ifndef _SORT_RANDOM + #define _SORT_RANDOM + int gen_rand(int min, int max); +#endif diff --git a/src/random.c b/src/random.c new file mode 100644 index 0000000..07b2dac --- /dev/null +++ b/src/random.c @@ -0,0 +1,12 @@ +#include +#include + +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; +} From 4acb044c2f0ae96039d09fea5379f2affb06e128 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Wed, 7 Nov 2018 14:48:14 -0300 Subject: [PATCH 2/3] fix incorrect cleaning of informe --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9f80acf..31c3f17 100644 --- a/Makefile +++ b/Makefile @@ -20,9 +20,10 @@ endif clean: cleansort cleaninforme cleansort: - rm -f src/*.o sort Informe.pdf + rm -f src/*.o sort cleaninforme: make -C doc clean + rm -f Informe.pdf .PHONY: all sort informe clean cleansort cleaninforme From 954e581c449ed4542b1bd81bf1d5761414bb1186 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Wed, 7 Nov 2018 14:49:51 -0300 Subject: [PATCH 3/3] add copyright info --- src/include/random.h | 15 +++++++++++++++ src/random.c | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/include/random.h b/src/include/random.h index c2eabd0..ce87841 100644 --- a/src/include/random.h +++ b/src/include/random.h @@ -1,3 +1,18 @@ +/* + * Copyright 2018 Christopher Cromer + * Copyright 2018 Rodolfo Cuevas + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #ifndef _SORT_RANDOM #define _SORT_RANDOM int gen_rand(int min, int max); diff --git a/src/random.c b/src/random.c index 07b2dac..ae1cd28 100644 --- a/src/random.c +++ b/src/random.c @@ -1,3 +1,18 @@ +/* + * Copyright 2018 Christopher Cromer + * Copyright 2018 Rodolfo Cuevas + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #include #include