File: isaac.h

package info (click to toggle)
gnubg 0.90%2B20091206-4
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 23,660 kB
  • ctags: 7,575
  • sloc: ansic: 92,588; xml: 13,661; sh: 1,058; makefile: 473; python: 429; yacc: 295; sql: 237; lex: 221; php: 103; cs: 81; awk: 25
file content (56 lines) | stat: -rw-r--r-- 1,619 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 $Id: isaac.h,v 1.3 2006/10/27 19:44:41 Superfly_Jon Exp $
------------------------------------------------------------------------------
isaac.h: definitions for a random number generator
MODIFIED:
  960327: Creation (addition of randinit, really)
  970719: use context, not global variables, for internal state
  980324: renamed seed to flag
  980605: recommend RANDSIZL=4 for noncryptography.
  991209: modified for inclusion with GNU Backgammon by Gary Wong
------------------------------------------------------------------------------
*/

#include "isaacs.h"

#ifndef _ISAAC_H_
#define _ISAAC_H_

#define RANDSIZL   (4)  /* I recommend 8 for crypto, 4 for simulations */
#define RANDSIZ    (1<<RANDSIZL)

/* context of random number generator */
struct randctx
{
  ub4 randcnt;
  ub4 randrsl[RANDSIZ];
  ub4 randmem[RANDSIZ];
  ub4 randa;
  ub4 randb;
  ub4 randc;
};
typedef  struct randctx  randctx;

/*
------------------------------------------------------------------------------
 If (flag==TRUE), then use the contents of randrsl[0..RANDSIZ-1] as the seed.
------------------------------------------------------------------------------
*/
void irandinit( randctx *r, word flag );

void isaac( randctx *r );


/*
------------------------------------------------------------------------------
 Call irand(/o_ randctx *r _o/) to retrieve a single 32-bit random value
------------------------------------------------------------------------------
*/
#define irand(r) \
   (!(r)->randcnt-- ? \
     (isaac(r), (r)->randcnt=RANDSIZ-1, (r)->randrsl[(r)->randcnt]) : \
     (r)->randrsl[(r)->randcnt])

#endif