78
78
directly representable in type RANDOM_TYPE, so we do instead:
79
79
divisor = MAX_UINT32/size
80
80
*************************************************************************/
81
RANDOM_TYPE myrand_debug(RANDOM_TYPE size,
82
const char *called_as, int line, const char *file)
81
RANDOM_TYPE myrand_debug(RANDOM_TYPE size, const char *called_as,
82
int line, const char *file)
84
84
RANDOM_TYPE new_rand, divisor, max;
110
110
rand_state.v[rand_state.x] = new_rand;
112
112
if (++bailout > 10000) {
113
freelog(LOG_ERROR, "%s(%lu) = %lu bailout at line %d of %s",
114
called_as, (unsigned long)size, (unsigned long)new_rand, line, file);
113
freelog(LOG_ERROR, "%s(%lu) = %lu bailout at %s:%d",
114
called_as, (unsigned long)size, (unsigned long)new_rand, file, line);
127
freelog(LOG_RAND, "%s(%lu) = %lu at line %d of %s",
128
called_as, (unsigned long)size, (unsigned long)new_rand, line, file);
127
freelog(LOG_RAND, "%s(%lu) = %lu at %s:%d",
128
called_as, (unsigned long)size, (unsigned long)new_rand, file, line);
213
213
/*************************************************************************
214
214
Test one aspect of randomness, using n numbers.
215
Reports results to LOG_NORMAL; with good randomness, behaviourchange
215
Reports results to LOG_TEST; with good randomness, behaviourchange
216
216
and behavioursame should be about the same size.
217
217
Tests current random state; saves and restores state, so can call
218
218
without interrupting current sequence.
243
243
old_value = new_value;
245
freelog(LOG_NORMAL, "test_random1(%d) same: %d, change: %d",
245
freelog(LOG_TEST, "test_random1(%d) same: %d, change: %d",
246
246
n, behavioursame, behaviourchange);
248
248
/* restore state: */
249
249
set_myrand_state(saved_state);
252
/*************************************************************************
253
Local pseudo-random function for repeatedly reaching the same result,
254
instead of myrand(). Primarily needed for tiles.
256
Use an invariant equation for seed.
257
Result is 0 to (size - 1).
258
*************************************************************************/
259
RANDOM_TYPE myrandomly_debug(RANDOM_TYPE seed, RANDOM_TYPE size,
260
const char *called_as, int line, const char *file)
264
#define LARGE_PRIME (10007)
265
#define SMALL_PRIME (1009)
267
/* Check for overflow and underflow */
268
assert(seed < MAX_UINT32 / LARGE_PRIME);
269
assert(size < SMALL_PRIME);
271
result = ((seed * LARGE_PRIME) % SMALL_PRIME) % size;
273
freelog(LOG_RAND, "%s(%lu,%lu) = %lu at %s:%d",
274
called_as, (unsigned long)seed, (unsigned long)size,
275
(unsigned long)result, file, line);