1/*
2 *   Copyright (c) International Business Machines Corp., 2001-2004
3 *
4 *   This program is free software;  you can redistribute it and/or modify
5 *   it under the terms of the GNU General Public License as published by
6 *   the Free Software Foundation; either version 2 of the License, or
7 *   (at your option) any later version.
8 *
9 *   This program is distributed in the hope that it will be useful,
10 *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
11 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
12 *   the GNU General Public License for more details.
13 *
14 *   You should have received a copy of the GNU General Public License
15 *   along with this program;  if not, write to the Free Software
16 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18#ifndef _MTINT_H_
19#define _MTINT_H_
20
21#include "config.h"
22
23#include <stdlib.h>
24#include <sys/types.h>
25#include <inttypes.h>
26
27/* A guess of how many random bytes (not bits) */
28/* will be consumed per iteration */
29/* This is multiplied by the iteration count */
30/* to get the size of the array in init_random() */
31#define AVG_ITR_RNDBTS 2
32
33/* Set a cap on the size of the array, note this */
34/* is multiplied by AVG_ITR_RNDBTS */
35#define MAX_RANDBUF_SIZE (10 * 1024)
36
37#define MIN_RANDBUF_SIZE 1024
38
39
40typedef struct randdata {
41	int size;
42	uint8_t *mt; /* the array of random bits  */
43	int mti; /* mti==N+1 means mt[N] is not initialized */
44
45	/* fallback random source, lrand48_r() */
46#ifdef HAVE_LRAND48_R
47	struct drand48_data data;
48#endif
49} randdata_t;
50
51uint32_t getrandom(randdata_t *rd, uint32_t mod);
52uint64_t getllrandom(randdata_t *rd, uint64_t mod);
53
54/* pass in thread-local state, and est. number of "uses" */
55/* pass in 0 for size if size is unknown/not important */
56void init_random(randdata_t *state, uint32_t size);
57void destroy_random(randdata_t *rd);
58void randcleanup(void);
59
60#endif
61