From 2b406bce51c003ae0e1cd94cd4fe534c441678ed Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 7 Dec 2017 17:45:29 +0300 Subject: [PATCH] Pre-seed the random generator in the Lua environment #127 --- src/run.c | 14 ++++++++++++++ src/studio.c | 9 --------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/run.c b/src/run.c index 9f5cf18..2565d75 100644 --- a/src/run.c +++ b/src/run.c @@ -24,6 +24,7 @@ #include "console.h" #include "fs.h" #include "ext/md5.h" +#include static void onTrace(void* data, const char* text, u8 color) { @@ -166,6 +167,17 @@ static void processDoFile(void* data, char* dst) return; } +static void preseed() +{ +#if defined(__MACOSX__) + srandom(time(NULL)); + random(); +#else + srand(time(NULL)); + rand(); +#endif +} + void initRun(Run* run, Console* console, tic_mem* tic) { *run = (Run) @@ -203,4 +215,6 @@ void initRun(Run* run, Console* console, tic_mem* tic) if(data) SDL_free(data); } + + preseed(); } diff --git a/src/studio.c b/src/studio.c index 738fc2a..86699ff 100644 --- a/src/studio.c +++ b/src/studio.c @@ -41,7 +41,6 @@ #include "fs.h" #include -#include #include "ext/net/SDL_net.h" #include "ext/gif.h" #include "ext/md5.h" @@ -2431,14 +2430,6 @@ void onEmscriptenWgetError(const char* error) {} s32 main(s32 argc, char **argv) { -#if defined(__MACOSX__) - srandom(time(NULL)); - random(); -#else - srand(time(NULL)); - rand(); -#endif - setbuf(stdout, NULL); studio.argc = argc; studio.argv = argv;