every platform provides sys_random_seed() and SYS_RANDOM_SEED goes away

This commit is contained in:
nhmall
2019-01-17 18:30:56 -05:00
committed by Patric Mueller
parent 97b8d0a50b
commit 0a430cab11
11 changed files with 27 additions and 42 deletions

View File

@@ -35,8 +35,6 @@
/*#define CHANGE_COLOR*/ /* allow palette changes */ /*#define CHANGE_COLOR*/ /* allow palette changes */
#define SELECTSAVED /* Provide menu of saved games to choose from at start */ #define SELECTSAVED /* Provide menu of saved games to choose from at start */
#define SYS_RANDOM_SEED /* Use random seed derived from CNG */
/* /*
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* The remaining code shouldn't need modification. * The remaining code shouldn't need modification.

View File

@@ -423,7 +423,6 @@
# define DEV_RANDOM "/dev/random" # define DEV_RANDOM "/dev/random"
# endif # endif
#endif #endif
#define SYS_RANDOM_SEED
#endif /* UNIXCONF_H */ #endif /* UNIXCONF_H */
#endif /* UNIX */ #endif /* UNIX */

View File

@@ -257,7 +257,6 @@ typedef __mode_t mode_t;
# define Rand() rand() # define Rand() rand()
# endif # endif
#endif #endif
#define SYS_RANDOM_SEED
#ifndef __GNUC__ #ifndef __GNUC__
#ifndef bcopy #ifndef bcopy

View File

@@ -850,24 +850,6 @@ extern struct tm *FDECL(localtime, (time_t *));
#endif #endif
STATIC_DCL struct tm *NDECL(getlt); STATIC_DCL struct tm *NDECL(getlt);
#ifdef SYS_RANDOM_SEED
extern unsigned long NDECL(sys_random_seed);
#endif
/* Returns a number suitable as seed for the random number generator. */
static unsigned long
get_random_seed()
{
unsigned long seed = 0;
#ifdef SYS_RANDOM_SEED
/* Platform-specific seed if one is provided */
seed = sys_random_seed();
#else
seed = (unsigned long) getnow(); /* time((TIME_type) 0) */
#endif
return seed;
}
/* Sets the seed for the random number generator */ /* Sets the seed for the random number generator */
static void static void
set_random(unsigned long seed) set_random(unsigned long seed)
@@ -898,6 +880,11 @@ set_random(unsigned long seed)
#endif #endif
} }
/* An appropriate version of this must always be provided in
port-specific code somewhere. It returns a number suitable
as seed for the random number generator */
extern unsigned long NDECL(sys_random_seed);
/* /*
* Initializes the random number generator. * Initializes the random number generator.
* Only call once. * Only call once.
@@ -905,19 +892,15 @@ set_random(unsigned long seed)
void void
init_random() init_random()
{ {
unsigned long seed = get_random_seed(); set_random(sys_random_seed());
set_random(seed);
} }
/* Reshuffles the random number generator. */ /* Reshuffles the random number generator. */
void void
reseed_random() reseed_random()
{ {
/* only reseed if we are certain that the seed generation is unguessable /* reseed */
* by the players. */
#if defined(SYS_RANDOM_SEED)
init_random(); init_random();
#endif
} }
time_t time_t

View File

@@ -519,4 +519,15 @@ unsigned setvalue;
return (regs.x.dx); return (regs.x.dx);
} }
unsigned long
sys_random_seed(VOID_ARGS)
{
unsigned long ourseed = 0UL;
time_t datetime = 0;
(void) time(&datetime);
ourseed = (unsigned long) datetime;
return ourseed;
}
#endif /* MSDOS */ #endif /* MSDOS */

View File

@@ -765,7 +765,6 @@ error:
} }
#endif #endif
#ifdef SYS_RANDOM_SEED
unsigned long unsigned long
sys_random_seed() sys_random_seed()
{ {
@@ -790,6 +789,5 @@ sys_random_seed()
#endif #endif
return seed; return seed;
} }
#endif /* SYS_RANDOM_SEED */
/*unixmain.c*/ /*unixmain.c*/

View File

@@ -465,7 +465,6 @@ wd_message()
You("are in non-scoring explore/discovery mode."); You("are in non-scoring explore/discovery mode.");
} }
#ifdef SYS_RANDOM_SEED
unsigned long unsigned long
sys_random_seed() sys_random_seed()
{ {
@@ -481,6 +480,5 @@ sys_random_seed()
} }
return seed; return seed;
} }
#endif
/*vmsmain.c*/ /*vmsmain.c*/

View File

@@ -73,8 +73,8 @@ DEBUGINFO = Y
# PDCurses header (.h) files and PDCURSES_C to the location # PDCurses header (.h) files and PDCURSES_C to the location
# of your PDCurses C files. # of your PDCurses C files.
# #
ADD_CURSES=Y #ADD_CURSES=Y
PDCURSES_TOP=..\..\pdcurses #PDCURSES_TOP=..\..\pdcurses
# #
#============================================================================== #==============================================================================
# This marks the end of the BUILD DECISIONS section. # This marks the end of the BUILD DECISIONS section.

View File

@@ -681,7 +681,8 @@ char *name;
return; return;
} }
#ifdef SYS_RANDOM_SEED #include <bcrypt.h> /* Windows Crypto Next Gen (CNG) */
#ifndef STATUS_SUCCESS #ifndef STATUS_SUCCESS
#define STATUS_SUCCESS 0 #define STATUS_SUCCESS 0
#endif #endif
@@ -692,8 +693,6 @@ char *name;
#define STATUS_UNSUCCESSFUL 0xC0000001 #define STATUS_UNSUCCESSFUL 0xC0000001
#endif #endif
#include <bcrypt.h> /* Windows Crypto Next Gen (CNG) */
unsigned long unsigned long
sys_random_seed(VOID_ARGS) sys_random_seed(VOID_ARGS)
{ {
@@ -727,7 +726,6 @@ sys_random_seed(VOID_ARGS)
} }
return ourseed; return ourseed;
} }
#endif /* SYS_RANDOM_SEED */
#endif /* WIN32 */ #endif /* WIN32 */

View File

@@ -37,7 +37,7 @@
<PreprocessorDefinitions>TILES;WIN32CON;DLB;MSWIN_GRAPHICS;SAFEPROCS;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>TILES;WIN32CON;DLB;MSWIN_GRAPHICS;SAFEPROCS;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;winmm.lib;Winmm.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;winmm.lib;Winmm.lib;bcrypt.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
@@ -76,6 +76,7 @@
<ClCompile Include="$(SrcDir)hack.c" /> <ClCompile Include="$(SrcDir)hack.c" />
<ClCompile Include="$(SrcDir)hacklib.c" /> <ClCompile Include="$(SrcDir)hacklib.c" />
<ClCompile Include="$(SrcDir)invent.c" /> <ClCompile Include="$(SrcDir)invent.c" />
<ClCompile Include="$(SrcDir)isaac64.c" />
<ClCompile Include="$(SrcDir)light.c" /> <ClCompile Include="$(SrcDir)light.c" />
<ClCompile Include="$(SrcDir)lock.c" /> <ClCompile Include="$(SrcDir)lock.c" />
<ClCompile Include="$(SrcDir)mail.c" /> <ClCompile Include="$(SrcDir)mail.c" />
@@ -151,7 +152,6 @@
<ClCompile Include="$(SrcDir)zap.c" /> <ClCompile Include="$(SrcDir)zap.c" />
<ClCompile Include="$(SysShareDir)cppregex.cpp" /> <ClCompile Include="$(SysShareDir)cppregex.cpp" />
<ClCompile Include="$(SysShareDir)nhlan.c" /> <ClCompile Include="$(SysShareDir)nhlan.c" />
<ClCompile Include="$(SysShareDir)random.c" />
<ClCompile Include="$(SysWinntDir)ntsound.c" /> <ClCompile Include="$(SysWinntDir)ntsound.c" />
<ClCompile Include="$(SysWinntDir)nttty.c" /> <ClCompile Include="$(SysWinntDir)nttty.c" />
<ClCompile Include="$(SysWinntDir)stubs.c"> <ClCompile Include="$(SysWinntDir)stubs.c">
@@ -194,6 +194,7 @@
<ClInclude Include="$(IncDir)func_tab.h" /> <ClInclude Include="$(IncDir)func_tab.h" />
<ClInclude Include="$(IncDir)global.h" /> <ClInclude Include="$(IncDir)global.h" />
<ClInclude Include="$(IncDir)hack.h" /> <ClInclude Include="$(IncDir)hack.h" />
<ClInclude Include="$(IncDir)isaac64.h" />
<ClInclude Include="$(IncDir)lev.h" /> <ClInclude Include="$(IncDir)lev.h" />
<ClInclude Include="$(IncDir)mextra.h" /> <ClInclude Include="$(IncDir)mextra.h" />
<ClInclude Include="$(IncDir)mfndpos.h" /> <ClInclude Include="$(IncDir)mfndpos.h" />

View File

@@ -28,7 +28,7 @@
</ResourceCompile> </ResourceCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<AdditionalDependencies>comctl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>comctl32.lib;winmm.lib;bcrypt.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
<Manifest> <Manifest>
<AdditionalManifestFiles>$(WinWin32Dir)NethackW.exe.manifest;%(AdditionalManifestFiles)</AdditionalManifestFiles> <AdditionalManifestFiles>$(WinWin32Dir)NethackW.exe.manifest;%(AdditionalManifestFiles)</AdditionalManifestFiles>
@@ -70,6 +70,7 @@
<ClCompile Include="$(SrcDir)hack.c" /> <ClCompile Include="$(SrcDir)hack.c" />
<ClCompile Include="$(SrcDir)hacklib.c" /> <ClCompile Include="$(SrcDir)hacklib.c" />
<ClCompile Include="$(SrcDir)invent.c" /> <ClCompile Include="$(SrcDir)invent.c" />
<ClCompile Include="$(SrcDir)isaac64.c" />
<ClCompile Include="$(SrcDir)light.c" /> <ClCompile Include="$(SrcDir)light.c" />
<ClCompile Include="$(SrcDir)lock.c" /> <ClCompile Include="$(SrcDir)lock.c" />
<ClCompile Include="$(SrcDir)mail.c" /> <ClCompile Include="$(SrcDir)mail.c" />
@@ -146,7 +147,6 @@
<ClCompile Include="$(SrcDir)zap.c" /> <ClCompile Include="$(SrcDir)zap.c" />
<ClCompile Include="$(SysShareDir)cppregex.cpp" /> <ClCompile Include="$(SysShareDir)cppregex.cpp" />
<ClCompile Include="$(SysShareDir)nhlan.c" /> <ClCompile Include="$(SysShareDir)nhlan.c" />
<ClCompile Include="$(SysShareDir)random.c" />
<ClCompile Include="$(SysWinntDir)ntsound.c" /> <ClCompile Include="$(SysWinntDir)ntsound.c" />
<ClCompile Include="$(SysWinntDir)stubs.c"> <ClCompile Include="$(SysWinntDir)stubs.c">
<PreprocessorDefinitions>TTYSTUB;</PreprocessorDefinitions> <PreprocessorDefinitions>TTYSTUB;</PreprocessorDefinitions>