From 855b0554734056d63920390b8ff05df253bc9266 Mon Sep 17 00:00:00 2001 From: Eliah Rebstock <elireb54@outlook.com> Date: Fri, 18 Jan 2019 22:10:27 +0100 Subject: [PATCH] Remove utils/rnd --- Makefile | 1 - include/log_action.h | 2 -- include/logsim.h | 1 - include/utils/rnd.h | 12 ------------ src/log.c | 6 +++--- src/logcom.c | 1 - src/loged.c | 8 +++++--- src/logsim.c | 6 +++--- src/logsimh.c | 2 +- src/screen.c | 6 +++--- src/utils/rnd.c | 25 ------------------------- 11 files changed, 15 insertions(+), 55 deletions(-) delete mode 100644 include/utils/rnd.h delete mode 100644 src/utils/rnd.c diff --git a/Makefile b/Makefile index 9abcef4..c42fa71 100644 --- a/Makefile +++ b/Makefile @@ -82,7 +82,6 @@ UTILSOBJ = $(TARGET_DIR)/utils/sysdevs.o \ $(TARGET_DIR)/utils/strings.o \ $(TARGET_DIR)/utils/strlist.o \ $(TARGET_DIR)/utils/newasm.o \ - $(TARGET_DIR)/utils/rnd.o \ $(TARGET_DIR)/utils/regex.o \ $(TARGET_DIR)/utils/p2c.o \ diff --git a/include/log_action.h b/include/log_action.h index d497c14..135a7ce 100644 --- a/include/log_action.h +++ b/include/log_action.h @@ -310,8 +310,6 @@ typedef struct log_action_t FILE **tracefile; - long rndseed; /** Seed for RAND funtion */ - char *homedirname; enum diff --git a/include/logsim.h b/include/logsim.h index 3abc8d2..c66da07 100644 --- a/include/logsim.h +++ b/include/logsim.h @@ -6,7 +6,6 @@ #include "logdig.h" #include "logsima.h" #include "logsimed.h" -#include <utils/rnd.h> #include <graphics/newkbd.h> #include <utils/newasm.h> #include <graphics/newci.h> diff --git a/include/utils/rnd.h b/include/utils/rnd.h deleted file mode 100644 index 65607ed..0000000 --- a/include/utils/rnd.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef RND_H -#define RND_H - -#include <utils/p2c.h> - -/** - * Use the c library random methods - */ -void P_random() DEPRECATED; -long P_rand() DEPRECATED; - -#endif /* RND_H */ diff --git a/src/log.c b/src/log.c index 285f97b..11e9ee2 100644 --- a/src/log.c +++ b/src/log.c @@ -34,6 +34,7 @@ #include <unistd.h> #include <time.h> +#include <stdlib.h> #include <string.h> @@ -42,7 +43,6 @@ #include "logdef.h" #include <utils/sysglobals.h> #include <utils/sysdevs.h> -#include <utils/rnd.h> /*homeless orphans*/ @@ -1316,7 +1316,7 @@ void tracemessage(char *msg) do { sprintf(tracefname, "/tmp/%.10s%03ld", - cuserid(NULL), P_rand(&gg.rndseed, 1000L)); + cuserid(NULL), rand() % 1000L); } while (access(tracefname, F_OK) == 0); } @@ -14112,7 +14112,6 @@ static void initialize() gg.host = log_host_log; gg.toolbase = NULL; inithooks(); - gg.rndseed = timers_sysclock(); gg.simstate = simst_null; gg.simstatetool = NULL; for (i = 0; i < maxgatesfiles; i++) @@ -14592,6 +14591,7 @@ int main(int argc, char * argv[]) nc_text_in_window = 1; PASCAL_MAIN(argc, argv); + srand(time(NULL)); tracefile = NULL; dumpfile = NULL; gg.initdone = false; diff --git a/src/logcom.c b/src/logcom.c index d59b627..50bfa21 100644 --- a/src/logcom.c +++ b/src/logcom.c @@ -37,7 +37,6 @@ the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "logdef.h" #include <utils/sysglobals.h> #include <utils/sysdevs.h> -#include <utils/rnd.h> #include <utils/misc.h> #include <graphics/newci.h> #include <utils/filepack.h> diff --git a/src/loged.c b/src/loged.c index 4641d7c..d673e6d 100644 --- a/src/loged.c +++ b/src/loged.c @@ -47,6 +47,8 @@ the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #define SIM_KIND #include <unistd.h> #include <utils/p2c.h> +#include <time.h> +#include <stdlib.h> #include "logdef.h" @@ -5306,7 +5308,7 @@ static void dumpcmd() else { if (*argument == '\0') { do { - sprintf(argument, "/tmp/loged%ld.ps", P_rand()); + sprintf(argument, "/tmp/loged%ld.ps", rand()); spool = 1; } while (access(argument, F_OK) == 0); } else @@ -6486,7 +6488,7 @@ char *argument_; char argument[256], fn[256]; strcpy(argument, argument_); - sprintf(fn, "/tmp/loged%03ld.text", P_rand()); + sprintf(fn, "/tmp/loged%03ld.text", rand()); if (*argument == '\0' && curkind != NULL) strcpy(argument, kind.name); writefile(fn, argument); @@ -6721,6 +6723,7 @@ int main(int argc, char * argv[]) nc_text_in_window = 1; PASCAL_MAIN(argc, argv); + srand(time(NULL)); if (P_argc > 1 && !strcmp(P_argv[1], "-p")) { /* piped mode */ nc_text_in_window = 0; @@ -6744,7 +6747,6 @@ int main(int argc, char * argv[]) gg.resetflag = false; gg.pwrflag = false; gg.refrflag = false; - gg.rndseed = timers_sysclock(); *gg.func = '\0'; gg.time = 0.0; gg.simstate = simst_null; diff --git a/src/logsim.c b/src/logsim.c index 221bd9b..e7f50db 100644 --- a/src/logsim.c +++ b/src/logsim.c @@ -39,6 +39,7 @@ #include <utils/p2c.h> +#include <stdlib.h> #include "logsim.h" #include "node.h" @@ -78,7 +79,7 @@ static const histcolortabletype histcolortable = { -static long rndseed, newsystime, oldsystime, stabtime, resetcounter; +static long newsystime, oldsystime, stabtime, resetcounter; static log_sigrec *vddsig, *gndsig, *resetsig; static int isstable, stabilizing, passready, maketimebid; static double nexttimebid; @@ -1214,7 +1215,7 @@ static void tstep_16(log_16_action *act) n = WITH->nbase; while (n != NULL) { - if (n->simtype == logsima_tool_16 && P_rand(&WITH->rndseed, 5L) == 0) + if (n->simtype == logsima_tool_16 && (rand() % 5L) == 0) { ni = (nodeinfo *)n->info; ni->v = ni->v00; @@ -1515,7 +1516,6 @@ void Log_16_proc(log_action_t *lact) if (*WITH->acttool->comment == '\0') strcpy(WITH->acttool->comment, "Digital simulator"); logsima_init(); - WITH->rndseed = timers_sysclock(); newsystime = 0; vddsig = NULL; gndsig = NULL; diff --git a/src/logsimh.c b/src/logsimh.c index cc89c0c..a93efd6 100644 --- a/src/logsimh.c +++ b/src/logsimh.c @@ -4095,7 +4095,7 @@ static void dodump(struct LOC_compilepage *LINK) char STR2[256]; f = NULL; - sprintf(buf, "/spool/apple.text/dig%ld", P_rand()); + sprintf(buf, "/spool/apple.text/dig%ld", rand()); sprintf(STR2, "Writing to dump file %s", buf); (*logsima_action.lact->hook.vmessage)(STR2); if (f != NULL) diff --git a/src/screen.c b/src/screen.c index f718122..948f698 100644 --- a/src/screen.c +++ b/src/screen.c @@ -466,14 +466,14 @@ void addrabbit() } if (j == -1) { - j = P_rand(&gg.rndseed, (long)rabtabsize) + 1; + j = (rand() % (long) rabtabsize) + 1; m_bunny((long)rabtable[j - 1].x, (long)rabtable[j - 1].y); rabtable[j - 1].next = 0; } do { - rx = P_rand(&gg.rndseed, across - 24L); - ry = P_rand(&gg.rndseed, baseline - 40L) + down - baseline + 30; + rx = rand() % (across - 24L); + ry = (rand() % (baseline - 40L)) + down - baseline + 30; nogood = false; for (i = 0; i < rabtabsize; i++) { diff --git a/src/utils/rnd.c b/src/utils/rnd.c deleted file mode 100644 index 47fb106..0000000 --- a/src/utils/rnd.c +++ /dev/null @@ -1,25 +0,0 @@ -#include <stdlib.h> -#include <utils/rnd.h> - - -void P_random(long *seed) -{ - - srand48(*seed); - *seed = lrand48(); -} - - -long P_rand(long *seed, long limit) -{ - - srand48(*seed); - *seed = lrand48(); - if (limit != 0) - return(abs(*seed % limit)); /* I know, I know. This skews probabilities */ - /* slightly toward low numbers unless limit */ - /* is a divisor of 2^32. Tough. */ - else - return(0); -} - -- GitLab