Freeciv-3.2: /fast/freeciv/nightly/S3_2/utility/rand.h Source File

Freeciv-3.2

Loading...
Searching...
No Matches
rand.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13#ifndef FC__RAND_H
14#define FC__RAND_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20#include <stdint.h>
21
22/* Utility */
23#include "log.h"
24#include "support.h" /* bool type */
25
26 typedef uint32_t RANDOM_TYPE;
27
28/* Usually random number generator results are logged at LOG_DEBUG level
29 * Uncommenting this, and using RANDLOG_ON and RANDLOG_OFF macros in
30 * the code will make them logged at LOG_NORMAL level, between such
31 * RANDLOG_ON / RANDLOG_OFF calls.
32 * Single RANDLOG_OFF will cancel any number of RANDLOG_ONs -
33 * there's no reference count involved. */
34/* #define LOG_RAND_VALUES */
35
36#ifdef LOG_RAND_VALUES
37
38void enable_randlog(bool enable);
39
40#define RANDLOG_ON enable_randlog(TRUE);
41#define RANDLOG_OFF enable_randlog(FALSE);
42
43#else /* LOG_RAND_VALUES */
44
45#define RANDLOG_ON
46#define RANDLOG_OFF
47
48#endif /* LOG_RAND_VALUES */
49
50 typedef struct {
51 RANDOM_TYPE v[56];
52 int j, k, x;
53 bool is_init; /* Initially FALSE for static storage */
54} RANDOM_STATE;
55
56#define fc_rand(_size) \
57 fc_rand_debug((_size), "fc_rand", __FC_LINE__, __FILE__)
58
59 RANDOM_TYPE fc_rand_debug(RANDOM_TYPE size, const char *called_as,
60 int line, const char *file);
61
62void fc_srand(RANDOM_TYPE seed);
63
64void fc_rand_uninit(void);
65bool fc_rand_is_init(void);
66 RANDOM_STATE fc_rand_state(void);
67void fc_rand_set_state(RANDOM_STATE state);
68
69void test_random1(int n);
70
71/*===*/
72
73#define fc_randomly(_seed, _size) \
74 fc_randomly_debug((_seed), (_size), "fc_randomly", __FC_LINE__, __FILE__)
75
76 RANDOM_TYPE fc_randomly_debug(RANDOM_TYPE seed, RANDOM_TYPE size,
77 const char *called_as,
78 int line, const char *file);
79
80#ifdef __cplusplus
81}
82#endif /* __cplusplus */
83
84#endif /* FC__RAND_H */
n
#define n
Definition astring.c:77
incite_cost
char * incite_cost
Definition comments.c:74
enable
#define enable(id)
Definition widget.h:223
log.h
fc_rand_is_init
bool fc_rand_is_init(void)
Definition rand.c:200
fc_rand_state
RANDOM_STATE fc_rand_state(void)
Definition rand.c:208
fc_rand_debug
RANDOM_TYPE fc_rand_debug(RANDOM_TYPE size, const char *called_as, int line, const char *file)
Definition rand.c:114
fc_srand
void fc_srand(RANDOM_TYPE seed)
Definition rand.c:161
RANDOM_TYPE
uint32_t RANDOM_TYPE
Definition rand.h:26
fc_randomly_debug
RANDOM_TYPE fc_randomly_debug(RANDOM_TYPE seed, RANDOM_TYPE size, const char *called_as, int line, const char *file)
Definition rand.c:292
test_random1
void test_random1(int n)
Definition rand.c:253
fc_rand_uninit
void fc_rand_uninit(void)
Definition rand.c:192
fc_rand_set_state
void fc_rand_set_state(RANDOM_STATE state)
Definition rand.c:229
size
size_t size
Definition specvec.h:72
x
struct sprite int x
Definition sprite_g.h:31
RANDOM_STATE
Definition rand.h:50
RANDOM_STATE::is_init
bool is_init
Definition rand.h:53
RANDOM_STATE::j
int j
Definition rand.h:52
support.h