Pre-seed the random generator in the Lua environment #127
This commit is contained in:
parent
31063a0818
commit
2b406bce51
14
src/run.c
14
src/run.c
|
@ -24,6 +24,7 @@
|
|||
#include "console.h"
|
||||
#include "fs.h"
|
||||
#include "ext/md5.h"
|
||||
#include <time.h>
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -41,7 +41,6 @@
|
|||
#include "fs.h"
|
||||
|
||||
#include <zlib.h>
|
||||
#include <time.h>
|
||||
#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;
|
||||
|
|
Loading…
Reference in New Issue