2 * isaac - A fast, high-quality pseudo-random number generator.
4 * ISAAC (Indirect, Shift, Accumulate, Add, and Count) is the most advanced of
5 * a series of pseudo-random number generators designed by Robert J. Jenkins
6 * Jr. in 1996: http://www.burtleburtle.net/bob/rand/isaac.html
9 * No efficient method is known for deducing their internal states.
10 * ISAAC requires an amortized 18.75 instructions to produce a 32-bit value.
11 * There are no cycles in ISAAC shorter than 2**40 values.
12 * The expected cycle length is 2**8295 values.
14 * ISAAC-64 generates a different sequence than ISAAC, but it uses the same
16 * It uses 64-bit arithmetic.
17 * It generates a 64-bit result every 19 instructions.
18 * All cycles are at least 2**72 values, and the average cycle length is
21 * An additional, important comment from Bob Jenkins in 2006:
23 * Seeding a random number generator is essentially the same problem as
24 * encrypting the seed with a block cipher.
25 * ISAAC should be initialized with the encryption of the seed by some
27 * I've provided a seeding routine in my implementations, which nobody has
28 * broken so far, but I have less faith in that initialization routine than
31 * A number of attacks on ISAAC have been published.
33 * [Pudo01] can recover the entire internal state and has expected running time
34 * less than the square root of the number of states, or 2**4121 (4.67E+1240).
37 * author="Marina Pudovkina",
38 * title="A Known Plaintext Attack on the {ISAAC} Keystream Generator",
39 * howpublished="Cryptology ePrint Archive, Report 2001/049",
41 * note="\url{http://eprint.iacr.org/2001/049}",
44 * [Auma06] reveals a large set of weak states, consisting of those for which
45 * the first value is repeated one or more times elsewhere in the state
49 * author="Jean-Philippe Aumasson",
50 * title="On the Pseudo-Random Generator {ISAAC}",
51 * howpublished="Cryptology ePrint Archive, Report 2006/438",
53 * note="\url{http://eprint.iacr.org/2006/438}",
56 * These induce a bias in the output relative to the repeated value.
58 * The seed values used as input below are scrambled before being used, so any
59 * duplicates in them do not imply duplicates in the resulting internal state,
60 * however the chances of some duplicate existing elsewhere in a random state
61 * are just over 255/2**32, or merely 1 in 16 million.
63 * Such states are, of course, much rarer in ISAAC-64.
65 * It is not clear if an attacker can tell from just the output if ISAAC is in
66 * a weak state, or deduce the full internal state in any case except that
67 * where all or almost all of the entries in the state vector are identical.
69 * Even if one does not trust the security of this PRNG (and, without a good
70 * source of entropy to seed it, one should not), ISAAC is an excellent source
71 * of high-quality random numbers for Monte Carlo simulations, etc.
73 * It is the fastest 32-bit generator among all of those that pass the
74 * statistical tests in the recent survey
75 * http://www.iro.umontreal.ca/~simardr/testu01/tu01.html, with the exception
76 * of Marsa-LFIB4, and it is quite competitive on 64-bit archtectures.
78 * Unlike Marsa-LFIB4 (and all other LFib generators), there are no linear
79 * dependencies between successive values, and unlike many generators found in
80 * libc implementations, there are no small periods in the least significant
81 * bits, or seeds which lead to very small periods in general.
86 * #include <ccan/isaac/isaac.h>
89 * static const char *CHEESE[3]={"Cheddar","Provolone","Camembert"};
91 * unsigned char seed[8];
94 * //N.B.: time() is not a good source of entropy.
95 * //Do not use it for cryptogrpahic purposes.
97 * //Print it out so we can reproduce problems if needed.
98 * printf("Seed: 0x%016llX\n",(long long)now);
99 * //And convert the time to a byte array so that we can reproduce the same
100 * // seed on platforms with different endianesses.
102 * seed[i]=(unsigned char)(now&0xFF);
105 * isaac_init(&isaac,seed,8);
106 * printf("0x%08lX\n",(long)isaac_next_uint32(&isaac));
107 * printf("%s\n",CHEESE[isaac_next_uint(&isaac,3)]);
108 * printf("%0.8G\n",isaac_next_float(&isaac));
109 * printf("%0.8G\n",isaac_next_signed_float(&isaac));
110 * printf("%0.18G\n",isaac_next_double(&isaac));
111 * printf("%0.18G\n",isaac_next_signed_double(&isaac));
115 * License: CC0 (Public domain)
117 * // We actually depend on the LGPL ilog routines, so not PD :(
118 * license_depends_compat FAIL
124 int main(int _argc,const char *_argv[]){
125 /*Expect exactly one argument.*/
126 if(_argc!=2)return 1;
127 if(strcmp(_argv[1],"depends")==0){
128 printf("ccan/ilog\n");