From c718bdada0e16b36b6f0f68df54a3ee343f91e49 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20Z=C3=A1rev=C3=BAcky?= Date: Mon, 15 Jan 2018 22:20:07 +0100 Subject: [PATCH] Use standard names for rand() and srand(). --- uspace/app/tetris/tetris.c | 6 +++--- uspace/dist/src/c/demos/tetris/tetris.c | 6 +++--- uspace/lib/c/generic/stdlib.c | 6 +++--- uspace/lib/c/generic/uuid.c | 4 ++-- uspace/lib/c/include/stdlib.h | 7 ++----- uspace/lib/posix/source/stdlib.c | 4 ++-- uspace/srv/net/tcp/ncsim.c | 4 ++-- 7 files changed, 17 insertions(+), 20 deletions(-) diff --git a/uspace/app/tetris/tetris.c b/uspace/app/tetris/tetris.c index 5e1090600..728c6f89f 100644 --- a/uspace/app/tetris/tetris.c +++ b/uspace/app/tetris/tetris.c @@ -155,9 +155,9 @@ static void elide(void) const struct shape *randshape(void) { - const struct shape *tmp = &shapes[random() % 7]; + const struct shape *tmp = &shapes[rand() % 7]; int i; - int j = random() % 4; + int j = rand() % 4; for (i = 0; i < j; i++) tmp = &shapes[classic ? tmp->rotc : tmp->rot]; @@ -170,7 +170,7 @@ static void srandomdev(void) struct timeval tv; gettimeofday(&tv, NULL); - srandom(tv.tv_sec + tv.tv_usec / 100000); + srand(tv.tv_sec + tv.tv_usec / 100000); } static void tetris_menu_draw(int level) diff --git a/uspace/dist/src/c/demos/tetris/tetris.c b/uspace/dist/src/c/demos/tetris/tetris.c index b81c78f42..a57c8a102 100644 --- a/uspace/dist/src/c/demos/tetris/tetris.c +++ b/uspace/dist/src/c/demos/tetris/tetris.c @@ -156,9 +156,9 @@ static void elide(void) const struct shape *randshape(void) { - const struct shape *tmp = &shapes[random() % 7]; + const struct shape *tmp = &shapes[rand() % 7]; int i; - int j = random() % 4; + int j = rand() % 4; for (i = 0; i < j; i++) tmp = &shapes[classic ? tmp->rotc : tmp->rot]; @@ -171,7 +171,7 @@ static void srandomdev(void) struct timeval tv; gettimeofday(&tv, NULL); - srandom(tv.tv_sec + tv.tv_usec / 100000); + srand(tv.tv_sec + tv.tv_usec / 100000); } static void tetris_menu_draw(int level) diff --git a/uspace/lib/c/generic/stdlib.c b/uspace/lib/c/generic/stdlib.c index bede7db6a..75161c3c4 100644 --- a/uspace/lib/c/generic/stdlib.c +++ b/uspace/lib/c/generic/stdlib.c @@ -34,14 +34,14 @@ #include -static long glbl_seed = 1; +static int glbl_seed = 1; -long int random(void) +int rand(void) { return glbl_seed = ((1366 * glbl_seed + 150889) % RAND_MAX); } -void srandom(unsigned int seed) +void srand(unsigned int seed) { glbl_seed = seed % RAND_MAX; } diff --git a/uspace/lib/c/generic/uuid.c b/uspace/lib/c/generic/uuid.c index f69f613c0..659becf5c 100644 --- a/uspace/lib/c/generic/uuid.c +++ b/uspace/lib/c/generic/uuid.c @@ -51,10 +51,10 @@ errno_t uuid_generate(uuid_t *uuid) /* XXX This is a rather poor way of generating random numbers */ gettimeofday(&tv, NULL); - srandom(tv.tv_sec ^ tv.tv_usec); + srand(tv.tv_sec ^ tv.tv_usec); for (i = 0; i < uuid_bytes; i++) - uuid->b[i] = random(); + uuid->b[i] = rand(); /* Version 4 UUID from random or pseudo-random numbers */ uuid->b[8] = (uuid->b[8] & ~0xc0) | 0x40; diff --git a/uspace/lib/c/include/stdlib.h b/uspace/lib/c/include/stdlib.h index e3487938a..31559d235 100644 --- a/uspace/lib/c/include/stdlib.h +++ b/uspace/lib/c/include/stdlib.h @@ -41,11 +41,8 @@ #define RAND_MAX 714025 -#define rand() random() -#define srand(seed) srandom(seed) - -extern long int random(void); -extern void srandom(unsigned int seed); +extern int rand(void); +extern void srand(unsigned int seed); extern void abort(void) __attribute__((noreturn)); extern void exit(int) __attribute__((noreturn)); diff --git a/uspace/lib/posix/source/stdlib.c b/uspace/lib/posix/source/stdlib.c index 2bbba6e03..939be0ca7 100644 --- a/uspace/lib/posix/source/stdlib.c +++ b/uspace/lib/posix/source/stdlib.c @@ -376,7 +376,7 @@ void posix_free(void *ptr) */ int posix_rand(void) { - return (int) random(); + return (int) rand(); } /** @@ -386,7 +386,7 @@ int posix_rand(void) */ void posix_srand(unsigned int seed) { - srandom(seed); + srand(seed); } /** diff --git a/uspace/srv/net/tcp/ncsim.c b/uspace/srv/net/tcp/ncsim.c index 7de12a309..923882ab1 100644 --- a/uspace/srv/net/tcp/ncsim.c +++ b/uspace/srv/net/tcp/ncsim.c @@ -80,7 +80,7 @@ void tcp_ncsim_bounce_seg(inet_ep2_t *epp, tcp_segment_t *seg) tcp_rqueue_insert_seg(&rident, seg); return; - if (0 /*random() % 4 == 3*/) { + if (0 /*rand() % 4 == 3*/) { /* Drop segment */ log_msg(LOG_DEFAULT, LVL_ERROR, "NCSim dropping segment"); tcp_segment_delete(seg); @@ -93,7 +93,7 @@ void tcp_ncsim_bounce_seg(inet_ep2_t *epp, tcp_segment_t *seg) return; } - sqe->delay = random() % (1000 * 1000); + sqe->delay = rand() % (1000 * 1000); sqe->epp = *epp; sqe->seg = seg; -- 2.11.4.GIT