Merge branch 'countermeasures' into alex-and-isaac
This commit is contained in:
@@ -556,6 +556,7 @@ typedef unsigned char uchar;
|
||||
|
||||
#endif
|
||||
|
||||
#define USE_ISAAC64 /* Use cross-plattform, bundled RNG */
|
||||
|
||||
/* End of Section 4 */
|
||||
|
||||
|
||||
@@ -220,6 +220,7 @@ E NEARDATA boolean mrg_to_wielded;
|
||||
E NEARDATA boolean defer_see_monsters;
|
||||
|
||||
E NEARDATA boolean in_steed_dismounting;
|
||||
E NEARDATA boolean has_strong_rngseed;
|
||||
|
||||
E const int shield_static[];
|
||||
|
||||
|
||||
@@ -925,7 +925,8 @@ E char *FDECL(strstri, (const char *, const char *));
|
||||
#endif
|
||||
E boolean
|
||||
FDECL(fuzzymatch, (const char *, const char *, const char *, BOOLEAN_P));
|
||||
E void NDECL(setrandom);
|
||||
E void NDECL(init_random);
|
||||
E void NDECL(reseed_random);
|
||||
E time_t NDECL(getnow);
|
||||
E int NDECL(getyear);
|
||||
#if 0
|
||||
@@ -2103,6 +2104,10 @@ E void FDECL(genl_outrip, (winid, int, time_t));
|
||||
|
||||
/* ### rnd.c ### */
|
||||
|
||||
#ifdef USE_ISAAC64
|
||||
E void FDECL(init_isaac64, (unsigned long));
|
||||
E long NDECL(nhrand);
|
||||
#endif
|
||||
E int FDECL(rn2, (int));
|
||||
E int FDECL(rn2_on_display_rng, (int));
|
||||
E int FDECL(rnl, (int));
|
||||
|
||||
@@ -7,35 +7,47 @@
|
||||
#ifndef INTEGER_H
|
||||
#define INTEGER_H
|
||||
|
||||
#if defined(__STDC__) && __STDC__ >= 199101L
|
||||
|
||||
#if defined(__STDC__) && __STDC_VERSION__ >= 199101L
|
||||
/* The compiler claims to conform to C99. Use stdint.h */
|
||||
#include <stdint.h>
|
||||
#define SKIP_STDINT_WORKAROUND
|
||||
#else
|
||||
# if defined(HAS_STDINT_H)
|
||||
/* Some compilers have stdint.h but don't conform to all of C99. */
|
||||
#include <stdint.h>
|
||||
#define SKIP_STDINT_WORKAROUND
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef SKIP_STDINT_WORKAROUND /* !C99 */
|
||||
typedef unsigned char uint8_t;
|
||||
typedef short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
|
||||
#if defined(__WATCOMC__) && !defined(__386__)
|
||||
/* Open Watcom providing a 16 bit build for MS-DOS or OS/2 */
|
||||
/* int is 16 bits; use long for 32 bits */
|
||||
typedef long int32_t;
|
||||
typedef unsigned long uint32_t;
|
||||
#else
|
||||
/* Otherwise, assume either a 32- or 64-bit compiler */
|
||||
/* long may be 64 bits; use int for 32 bits */
|
||||
typedef int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#endif
|
||||
|
||||
typedef long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
|
||||
#endif /* !C99 */
|
||||
|
||||
/* Provide uint8, int16, uint16, int32, uint32, int64 and uint64 */
|
||||
typedef uint8_t uint8;
|
||||
typedef int16_t int16;
|
||||
typedef uint16_t uint16;
|
||||
typedef int32_t int32;
|
||||
typedef uint32_t uint32;
|
||||
|
||||
#else /* !C99 */
|
||||
|
||||
/* Provide uint8, int16, uint16, int32 and uint32 */
|
||||
typedef unsigned char uint8;
|
||||
typedef short int16;
|
||||
typedef unsigned short uint16;
|
||||
|
||||
#if defined(__WATCOMC__) && !defined(__386__)
|
||||
/* Open Watcom providing a 16 bit build for MS-DOS or OS/2 */
|
||||
/* int is 16 bits; use long for 32 bits */
|
||||
typedef long int32;
|
||||
typedef unsigned long uint32;
|
||||
#else
|
||||
/* Otherwise, assume either a 32- or 64-bit compiler */
|
||||
/* long may be 64 bits; use int for 32 bits */
|
||||
typedef int int32;
|
||||
typedef unsigned int uint32;
|
||||
#endif
|
||||
|
||||
#endif /* !C99 */
|
||||
typedef int64_t int64;
|
||||
typedef uint64_t uint64;
|
||||
|
||||
#endif /* INTEGER_H */
|
||||
|
||||
89
include/isaac64.h
Normal file
89
include/isaac64.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/* CC0 (Public domain) - see http://creativecommons.org/publicdomain/zero/1.0/ for details */
|
||||
#if !defined(_isaac64_H)
|
||||
# define _isaac64_H (1)
|
||||
# include <integer.h>
|
||||
|
||||
|
||||
|
||||
typedef struct isaac64_ctx isaac64_ctx;
|
||||
|
||||
|
||||
|
||||
#define ISAAC64_SZ_LOG (8)
|
||||
#define ISAAC64_SZ (1<<ISAAC64_SZ_LOG)
|
||||
#define ISAAC64_SEED_SZ_MAX (ISAAC64_SZ<<3)
|
||||
|
||||
|
||||
|
||||
/*ISAAC is the most advanced of a series of pseudo-random number generators
|
||||
designed by Robert J. Jenkins Jr. in 1996.
|
||||
http://www.burtleburtle.net/bob/rand/isaac.html
|
||||
This is the 64-bit version.
|
||||
To quote:
|
||||
ISAAC-64 generates a different sequence than ISAAC, but it uses the same
|
||||
principles.
|
||||
It uses 64-bit arithmetic.
|
||||
It generates a 64-bit result every 19 instructions.
|
||||
All cycles are at least 2**72 values, and the average cycle length is
|
||||
2**16583.*/
|
||||
struct isaac64_ctx{
|
||||
unsigned n;
|
||||
uint64_t r[ISAAC64_SZ];
|
||||
uint64_t m[ISAAC64_SZ];
|
||||
uint64_t a;
|
||||
uint64_t b;
|
||||
uint64_t c;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* isaac64_init - Initialize an instance of the ISAAC64 random number generator.
|
||||
* @_ctx: The ISAAC64 instance to initialize.
|
||||
* @_seed: The specified seed bytes.
|
||||
* This may be NULL if _nseed is less than or equal to zero.
|
||||
* @_nseed: The number of bytes to use for the seed.
|
||||
* If this is greater than ISAAC64_SEED_SZ_MAX, the extra bytes are
|
||||
* ignored.
|
||||
*/
|
||||
void isaac64_init(isaac64_ctx *_ctx,const unsigned char *_seed,int _nseed);
|
||||
|
||||
/**
|
||||
* isaac64_reseed - Mix a new batch of entropy into the current state.
|
||||
* To reset ISAAC64 to a known state, call isaac64_init() again instead.
|
||||
* @_ctx: The instance to reseed.
|
||||
* @_seed: The specified seed bytes.
|
||||
* This may be NULL if _nseed is zero.
|
||||
* @_nseed: The number of bytes to use for the seed.
|
||||
* If this is greater than ISAAC64_SEED_SZ_MAX, the extra bytes are
|
||||
* ignored.
|
||||
*/
|
||||
void isaac64_reseed(isaac64_ctx *_ctx,const unsigned char *_seed,int _nseed);
|
||||
/**
|
||||
* isaac64_next_uint64 - Return the next random 64-bit value.
|
||||
* @_ctx: The ISAAC64 instance to generate the value with.
|
||||
*/
|
||||
uint64_t isaac64_next_uint64(isaac64_ctx *_ctx);
|
||||
/**
|
||||
* isaac64_next_uint - Uniform random integer less than the given value.
|
||||
* @_ctx: The ISAAC64 instance to generate the value with.
|
||||
* @_n: The upper bound on the range of numbers returned (not inclusive).
|
||||
* This must be greater than zero and less than 2**64.
|
||||
* To return integers in the full range 0...2**64-1, use
|
||||
* isaac64_next_uint64() instead.
|
||||
* Return: An integer uniformly distributed between 0 and _n-1 (inclusive).
|
||||
*/
|
||||
uint64_t isaac64_next_uint(isaac64_ctx *_ctx,uint64_t _n);
|
||||
/**
|
||||
* isaac64_next_float - Uniform random float in the range [0,1).
|
||||
* @_ctx: The ISAAC64 instance to generate the value with.
|
||||
* Returns a high-quality float uniformly distributed between 0 (inclusive)
|
||||
* and 1 (exclusive).
|
||||
* All of the float's mantissa bits are random, e.g., the least significant bit
|
||||
* may still be non-zero even if the value is less than 0.5, and any
|
||||
* representable float in the range [0,1) has a chance to be returned, though
|
||||
* values very close to zero become increasingly unlikely.
|
||||
* To generate cheaper float values that do not have these properties, use
|
||||
* ldexpf((float)isaac64_next_uint64(_ctx),-64);
|
||||
*/
|
||||
|
||||
#endif
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
/* #define SHELL */ /* nt use of pcsys routines caused a hang */
|
||||
|
||||
#define RANDOM /* have Berkeley random(3) */
|
||||
#define TEXTCOLOR /* Color text */
|
||||
|
||||
#define EXEPATH /* Allow .exe location to be used as HACKDIR */
|
||||
@@ -25,8 +24,7 @@
|
||||
game */
|
||||
|
||||
#define SYSCF /* Use a global configuration */
|
||||
#define SYSCF_FILE "sysconf" /* Use a file to hold the SYSCF configuration \
|
||||
*/
|
||||
#define SYSCF_FILE "sysconf" /* Use a file to hold the SYSCF configuration */
|
||||
|
||||
#define DUMPLOG /* Enable dumplog files */
|
||||
/*#define DUMPLOG_FILE "nethack-%n-%d.log"*/
|
||||
@@ -35,9 +33,8 @@
|
||||
#define USER_SOUNDS
|
||||
|
||||
/*#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 */
|
||||
|
||||
/*
|
||||
* -----------------------------------------------------------------
|
||||
* The remaining code shouldn't need modification.
|
||||
@@ -131,6 +128,9 @@ extern void FDECL(interject, (int));
|
||||
/* suppress a warning in cppregex.cpp */
|
||||
#pragma warning(disable : 4101) /* unreferenced local variable */
|
||||
#endif
|
||||
#ifndef HAS_STDINT_H
|
||||
#define HAS_STDINT_H /* force include of stdint.h in integer.h */
|
||||
#endif
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* The following is needed for prototypes of certain functions */
|
||||
@@ -180,10 +180,17 @@ extern void FDECL(interject, (int));
|
||||
#include <time.h>
|
||||
|
||||
#define USE_STDARG
|
||||
#ifdef RANDOM
|
||||
|
||||
/* Use the high quality random number routines. */
|
||||
#define Rand() random()
|
||||
#ifdef USE_ISAAC64
|
||||
#undef RANDOM
|
||||
#else
|
||||
#define RANDOM
|
||||
#define Rand() random()
|
||||
#endif
|
||||
|
||||
/* Fall back to C's if nothing else, but this really isn't acceptable */
|
||||
#if !defined(USE_ISAAC64) && !defined(RANDOM)
|
||||
#define Rand() rand()
|
||||
#endif
|
||||
|
||||
|
||||
@@ -78,11 +78,12 @@
|
||||
#include <time.h>
|
||||
|
||||
/* the high quality random number routines */
|
||||
|
||||
#ifdef RANDOM
|
||||
#define Rand() random()
|
||||
#else
|
||||
#define Rand() rand()
|
||||
#ifndef USE_ISAAC64
|
||||
# ifdef RANDOM
|
||||
# define Rand() random()
|
||||
# else
|
||||
# define Rand() rand()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* file creation mask */
|
||||
|
||||
@@ -236,11 +236,13 @@
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#ifdef RANDOM
|
||||
/* Use the high quality random number routines. */
|
||||
#define Rand() random()
|
||||
#else
|
||||
#define Rand() rand()
|
||||
/* the high quality random number routines */
|
||||
#ifndef USE_ISAAC64
|
||||
# ifdef RANDOM
|
||||
# define Rand() random()
|
||||
# else
|
||||
# define Rand() rand()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef TOS
|
||||
|
||||
@@ -347,11 +347,14 @@
|
||||
#endif
|
||||
|
||||
/* Use the high quality random number routines. */
|
||||
#if defined(BSD) || defined(LINUX) || defined(ULTRIX) || defined(CYGWIN32) \
|
||||
/* the high quality random number routines */
|
||||
#ifndef USE_ISAAC64
|
||||
# if defined(BSD) || defined(LINUX) || defined(ULTRIX) || defined(CYGWIN32) \
|
||||
|| defined(RANDOM) || defined(__APPLE__)
|
||||
#define Rand() random()
|
||||
#else
|
||||
#define Rand() lrand48()
|
||||
# define Rand() random()
|
||||
# else
|
||||
# define Rand() lrand48()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef TIMED_DELAY
|
||||
@@ -408,5 +411,18 @@
|
||||
# define RUNTIME_PASTEBUF_SUPPORT
|
||||
#endif
|
||||
|
||||
/*
|
||||
* /dev/random is blocking on Linux, so there we default to /dev/urandom which
|
||||
* should still be good enough.
|
||||
* BSD systems usually have /dev/random that is supposed to be used.
|
||||
*/
|
||||
#ifdef LINUX
|
||||
# define DEV_RANDOM "/dev/urandom"
|
||||
#else
|
||||
# ifdef BSD
|
||||
# define DEV_RANDOM "/dev/random"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* UNIXCONF_H */
|
||||
#endif /* UNIX */
|
||||
|
||||
@@ -243,17 +243,19 @@ typedef __mode_t mode_t;
|
||||
#define rindex strrchr
|
||||
|
||||
/* Use the high quality random number routines. */
|
||||
#if defined(RANDOM)
|
||||
#define Rand() random()
|
||||
#ifndef USE_ISAAC64
|
||||
# if defined(RANDOM)
|
||||
# define Rand() random()
|
||||
/* VMS V7 adds these entry points to DECC$SHR; stick with the nethack-supplied
|
||||
code to avoid having to deal with version-specific conditionalized builds
|
||||
*/
|
||||
#define random nh_random
|
||||
#define srandom nh_srandom
|
||||
#define initstate nh_initstate
|
||||
#define setstate nh_setstate
|
||||
#else
|
||||
#define Rand() rand()
|
||||
# define random nh_random
|
||||
# define srandom nh_srandom
|
||||
# define initstate nh_initstate
|
||||
# define setstate nh_setstate
|
||||
# else
|
||||
# define Rand() rand()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef __GNUC__
|
||||
|
||||
@@ -141,11 +141,14 @@
|
||||
#define index strchr
|
||||
#define rindex strrchr
|
||||
#define USE_STDARG
|
||||
#ifdef RANDOM
|
||||
|
||||
/* Use the high quality random number routines. */
|
||||
#define Rand() random()
|
||||
#else
|
||||
#define Rand() rand()
|
||||
#ifndef USE_ISAAC64
|
||||
# ifdef RANDOM
|
||||
# define Rand() random()
|
||||
# else
|
||||
# define Rand() rand()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define FCMASK 0660 /* file creation mask */
|
||||
|
||||
Reference in New Issue
Block a user