You are on page 1of 5

Secondary Sources A Binary Sequence Generator Based on the

Bernasconi, R. (1987). Deconstruction and the possibility of ethics. In J. Kolakoski Sequence and Multiples of Odd Primes
Sallis (Ed.), Deconstruction and philosophy. Chicago: University of
Chicago Press.
Joel R. Noche
Caputo, J. (1993a). Against ethics: Contributions to a poetics of obligation Department of Mathematics and Natural Sciences
with constant reference to deconstruction, Studies in Continental
Thought. Bloomington: Indiana University Press. Abstract
Caputo, J. (1993b). Radical hermeneutics: Repetition, deconstruction and An earlier binary sequence generator is modified to yield
the hermeneutic project, Studies in Phenomenology and Existential better performance in the DIEHARD tests for randomness
Philosophy. Bloomington: Indiana University Press. of uniformly distributed numbers. The new generator
Caputo, J. (1997a). Deconstruction in a nutshell. New York: Fordham inverts every p bits of a modified Kolakoski sequence,
University Press. where p is a prime number, and does this for the first f odd
prime numbers. Samples from the resulting binary
Caputo, J. (1997b). The prayers and tears of Jacques Derrida: Religion sequence can be used in scientific applications requiring
without religion. Indianapolis: Indiana University Press. random numbers.
Cornell, D. (Ed.). (1992). Deconstruction and the possibility of justice. New Introduction
York: Routledge.
Large amounts of “random” numbers are currently needed by
Critchley, S. (1990). Derrida and deconstruction. In R. Kearney (Ed.), many applications (Hayes, 2001). In this work, numbers are said to
Routledge history of philosophy (vol. VII). London and New York:
be random if they perform well in commonly accepted statistical tests
Routledge.
of randomness. Pseudo-random number generators (PRNGs) usually
Critchley, S. (1992). The ethics of deconstruction: Derrida and Levinas. refer to generators of uniformly distributed numbers (often over the
Oxford: Blackwell. interval (0,1)). (Arbitrary distributions are usually generated by
Culler, J. (1983). On deconstruction. London: Routledge and Kegan Paul. applying transformations to these values.) PRNGs differ from (true)
random number generators (RNGs) in that the former perform
Kearney, R. (1999). Poetics of modernity. New York: Humanity Books.
deterministic operations on a seed value, while the latter rely on a
Levinas, E. (1969). Totality and infinity. (A. Lingis, Trans.). Pittsburgh: non-deterministic source of randomness (usually a physical process
Duquesne University Press. such as radioactive decay or thermal noise). Two (of many)
Norris, C. (1987). Derrida. Cambridge: Harvard University Press. properties that a “good” PRNG or RNG should have are: (1) the
numbers of bits ‘0’ and ‘1’ it produces should be almost equal, and
Rapaport, H. (2003). Later Derrida. New York: Routledge.
(2) the sequence should not repeat, that is, it should be non-periodic.
Sim, S. (1992). Beyond aesthetics. London: Harvester Wheatsheaf.
In an earlier work (Noche, 2004), a certain binary sequence
generator was proposed. It started with a Thue-Morse sequence 0, 1,
1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, … (sequence A010060 in Sloane
(2006)). This sequence is not periodic (Allouche & Shallit, 1999) and
the numbers of ‘0’s and ‘1’s in an infinite Thue-Morse sequence are
the same. This sequence, however, terribly fails commonly accepted
statistical tests of randomness.
It was shown in (Noche, 2004) that the algorithm used in that
work to generate the Thue-Morse sequence lead to an interesting
78 KAMAWOTAN vol. 1, no. 2, May 2007 College of Arts and Sciences, Ateneo de Naga University 79
method of adding “disorder” to the original sequence. The bits whose can affect the results of correlations tests and other tests (Davies,
order in the sequence was a multiple of a prime number p were 2000). In this work, both problems are avoided: the output is saved
inverted, and this was done sequentially for increasing p for the first f as a binary file (not a text file), and only byte-sized words are used to
odd prime numbers. (Odd prime numbers were chosen because no represent the sequence. Details of the tests and the associated p-
“disorder” is introduced by inverting all the even bits, that is, the values are in Marsaglia (1995). The results of the tests can be
multiples of the only even prime number, 2.) summarized by 146 p-values.
This generator is now modified by starting it with a The program presented in (Noche, 2004) called subroutines
Kolakoski sequence instead. A Kolakoski sequence is a sequence that from inside loops. The revised version listed in Appendix A does not
equals its own run length sequence (Kolakoski, 1965). The sequence use subroutine calls, resulting in improved performance.
{k (n )}∞n=0 = 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, … (sequence Four cases are tested: those involving the first f = 10, 100,
A000002 in Sloane (2006)) is the Kolakoski sequence that starts with 1000, and 2000 odd prime numbers. The cases labeled t10, t100,
‘1.’ Listed above are its first ten runs; the first run is ‘1,’ the second t1000, and t2000 use the Thue-Morse sequence, and those labeled
run is ‘2,2,’ the third run is ‘1,1,’ the fourth run is ‘2,’ and so on. The k10, k100, k1000, and k2000 use the Kolakoski sequence. (The latter
first run has k(1) = 1 element, the second run has k(2) = 2 elements, four cases use the program listed in Appendix B.) Each sequence is
the third run has k(3) = 2 elements, the fourth run has k(4) = 1 16,777,216 bytes long. (DIEHARD needs at least an 80 million bit
element, and so on. long test sequence for all of its tests to run.)
The Kolakoski sequence that starts with ‘2’ is 2, 2, 1, 1, 2, 1, For comparison, the results of the PRNG KISS (Marsaglia,
2, 2, 1, 2, 2, 1, 1, 2, 1, 1, … (sequence A078880 in Sloane (2006)). 1995) are also included. It “seems to pass all [the DIEHARD] tests
This is the version arbitrarily chosen in this work. A binary sequence and is highly recommended for speed and simplicity” (Marsaglia,
composed of ‘0’s and ‘1’s is desired, so the ‘2’s are arbitrarily 1995). The KISS sequence tested here is 11,468,800 bytes long and
converted into ‘0’s to get the binary sequence {x (n )}∞n=0 = 0, 0, 1, 1, 0, used the seed integers 1, 4, 3, and 44.
1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, …. Results
The Kolakoski sequence is not periodic (Kolakoski and Table 1 shows the run times for a computer with an Intel
Ucoluk, 1966) and it is conjectured (but not yet proven) that the Celeron 1.70 GHz processor, 256 MB of RAM, and a Microsoft
number of ‘0’s and ‘1’s in an infinite Kolakoski sequence are the Windows XP operating system. The KISS output file takes less than
same (Weisstein, 2006). a second to generate after the seed values are given.
Methodology Table 1. Run times (in seconds)
One popular way to test PRNGs and RNGs is the DIEHARD f Thue-Morse Thue-Morse Kolakoski
series of tests (Marsaglia, 1995). DIEHARD contains fifteen tests for (Noche, 2004) (Appendix A) (Appendix B)
randomness of uniformly distributed numbers. Care should be taken
10 13 4 8
when running these tests. For example, Marsaglia reports that the
100 18 7 11
hardware RNGs he tested failed “spectacularly.” Davies (1997)
found that the supposed failures were mostly due to a data handling 1000 26 15 18
error: each byte with a value of 10 was being recorded as two bytes 2000 29 16 20
with values of 13 and 10 (a carriage return followed by a line feed).
Another possible problem is the different conventions for the order in The p-values for the t10, t100, t1000, t2000, and KISS test
which the bits or bytes are stored in a word. The rearrangement of cases are listed in (Noche, 2004). (The program in Appendix A
bytes when copying between computers with different conventions yields the same DIEHARD p-values as the program in Noche (2004).)

80 KAMAWOTAN vol. 1, no. 2, May 2007 College of Arts and Sciences, Ateneo de Naga University 81
Due to space limitations, the p-values for the k10, k100, k1000, and Figure 2. Histogram of DIEHARD p-values (KISS sequence)
k2000 cases are not listed here. 140

Discussion
120

It is implied that if all the p-values of a sequence tested by


100
DIEHARD lie in the range (0.025, 0.975) then the sequence is said to
have passed all the DIEHARD tests. This is the reasoning behind the 80

claim in (Noche, 2004) that the sequence t2000 performed well in the
60
tests. A subsequent analysis of the data, however, shows that t2000’s
test results still leave more to be desired. 40

The histograms of the p-values for each Thue-Morse-based 20


test case are shown in Figure 1. Note that most of the p-values are in
the uppermost decile. The histogram for the KISS test case (Figure 2) 0
0.0-0.1
is more uniformly distributed. This seems to imply that a “more 0.1-0.2
0.2-0.3
0.3-0.4
0.4-0.5
random” sequence would have a more uniformly distributed set of p- 0.5-0.6
0.6-0.7 KISS
0.7-0.8
0.8-0.9
values in the DIEHARD tests. 0.9-1.0

Figure 1. Histograms of DIEHARD p-values (Thue-Morse-based Figure 3. Histograms of DIEHARD p-values (Kolakoski-based sequences)
sequences)
140
140

120
120

100
100

80
80

60
60

40
40

20
20

0 k10
0 t10 0.0-0.1 k100
0.1-0.2
t100 0.2-0.3 k1000
0.0-0.1 0.3-0.4
0.1-0.2 0.4-0.5
0.2-0.3 t1000 0.5-0.6 k2000
0.3-0.4 0.6-0.7
0.4-0.5 0.7-0.8
0.5-0.6 t2000 0.8-0.9
0.6-0.7 0.9-1.0
0.7-0.8
0.8-0.9
0.9-1.0

82 KAMAWOTAN vol. 1, no. 2, May 2007 College of Arts and Sciences, Ateneo de Naga University 83
Figure 3 shows the histograms for the Kolakoski-based test Sloane, N. (2006). The on-line encyclopedia of integer sequences. Retrieved
cases. It shows that even case k100 seems to have better test results April 2007, from http://www.research.att.com/~njas/sequences/
than case t2000. Weisstein, E. (2006). Kolakoski sequence. From MathWorld—A Wolfram
It must be mentioned, however, that all the Kolakoski-based Web Resource. Retrieved April 2007 from http://mathworld
.wolfram.com/KolakoskiSequence.html
test cases performed very poorly in the seventh DIEHARD test
(“Count the 1’s in a stream of bytes”). This can be seen in Table 2. Appendix A
/* improved version of the program presented in (Noche, 2004) */
Table 2. p-values for the seventh DIEHARD test (rounded off). /* source code for Microsoft Visual C++ 6.0 */

t10 t100 t1000 t2000 KISS k10 k100 k1000 k2000 #include <stdio.h>
p109 1.000 0.979 0.963 0.997 0.919 1.000 1.000 1.000 0.993 #include <stdlib.h>
p110 1.000 1.000 1.000 0.835 0.336 1.000 1.000 1.000 1.000
#define M 27
#define L 134217728
Conclusions #define B 16777216
#define F 2000
The binary sequence generator presented here is shown to #define MAXPRIME 17393
perform arguably better in a popular set of tests for randomness than /* F=10, MAXPRIME=31
an earlier work. In particular, case k100 has a shorter run time than F=100, MAXPRIME=547
case t2000 and its p-values are more uniformly distributed than those F=1000, MAXPRIME=7927
F=2000, MAXPRIME=17393 */
of case t2000.
void main(void)
References {
unsigned char bitconst[8] =
Allouche, J.-P., & Shallit, J. (1999). The ubiquitous Prouhet-Thue-Morse {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
sequence. In Sequences and Their Applications: Proceedings of unsigned long j = 0, k;
SETA ’98, Springer-Verlag, 1–16. unsigned short i;
unsigned char *x;
Davies, R. (1997). True random number generators. Retrieved April 2004, FILE *fp;
from http://www.robertnz. net/true_mg.html
unsigned short *prime;
Davies, R. (2000). Hardware random number generators. Retrieved April prime = (unsigned short *) malloc((F+1) * sizeof(unsigned
short));
2004, from http://www.robertnz.net/hwrng.html unsigned char *c;
c = (unsigned char *) malloc((MAXPRIME+1) * sizeof(unsigned
Hayes, B. (2001). Computing science: Randomness as a resource, American char));
Scientist, 89(4), 300–304.
for (i = 1; i <= MAXPRIME; i++)
Kolakoski, W. (1965). Self generating runs, Problem 5304. American c[i] = 1;
Mathematical Monthly, 72(6), 674. c[1] = 0;
prime[0] = 2;
Kolakoski, W., & Ucoluk, N. (1966). 5304. American Mathematical do
Monthly, 73(6), 681–682. {
for (i = prime[j]; i <= MAXPRIME; i += prime[j])
Marsaglia, G. (1995). The Marsaglia random number CDROM including the c[i] = 0;
DIEHARD battery of tests of randomness. Retrieved March 2004, i = prime[j] + 1;
while (c[i] == 0)
from http://stat.fsu.edu/pub/diehard/ i++;
prime[++j] = i;
Noche, J. (2004). A binary sequence generator based on the Thue-Morse }
sequence and multiples of primes. The Philippine Statistician, while (j < F);
53(1–4), 67–76. free(c);

84 KAMAWOTAN vol. 1, no. 2, May 2007 College of Arts and Sciences, Ateneo de Naga University 85
c = (unsigned char *) malloc((MAXPRIME+1) * sizeof(unsigned
x = (unsigned char *) malloc(B * sizeof(unsigned char)); char));

x[0] = 0x69; /* data types might need to be changed if F is increased */


x[1] = ~x[0];
for (i = 1; i < (M-3); i++) for (i = 1; i <= MAXPRIME; i++)
{ c[i] = 1;
k = 1 << i; /* k = 2^i */ c[1] = 0;
for (j = 0; j < k; j++) prime[0] = 2;
x[k+j] = ~x[j]; do
} {
for (i = prime[j]; i <= MAXPRIME; i += prime[j])
for (i = 1; i <= F; i++) c[i] = 0;
for (j = prime[i]-1; j < L; j += prime[i]) i = prime[j] + 1;
x[j/8] ^= bitconst[j%8]; while (c[i] == 0)
i++;
fp = fopen("t.dat", "wb"); prime[++j] = i;
fwrite(x, B, 1, fp); }
fclose(fp); while (j < F);
} free(c);

Appendix B /* create Kolakoski word */


/* source code for Microsoft Visual C++ 6.0 */ x = (unsigned char *) malloc(B * sizeof(unsigned char));
#include <stdio.h> x[0] = 0x34;
#include <stdlib.h> for (j = 1; j < B; j++)
x[j] = 0x00;
#define M 27
#define L 134217728 k = 8;
#define B 16777216 for (j = 5; k < L; j++)
#define F 2000 {
#define MAXPRIME 17393 x[k/8] |= bitconst[k%8];
k++;
/* F=10, MAXPRIME=31 if ((x[j/8] & bitconst[j%8]) == 0x00)
F=100, MAXPRIME=547 {
F=1000, MAXPRIME=7927 x[k/8] |= bitconst[k%8];
F=2000, MAXPRIME=17393 k++;
L is the length of the sequence in bits; L = 2^M }
B is the size of the sequence in bytes j++;
F is the number of (odd) primes to use k++;
MAXPRIME is the Fth odd prime (the (F+1)th prime) */ if ((x[j/8] & bitconst[j%8]) == 0x00)
k++;
void main(void) }
{
unsigned char bitconst[8] = /* invert bits that are multiples of the first F odd primes */
{0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
unsigned long j = 0, k; for (i = 1; i <= F; i++)
unsigned short i; for (j = prime[i]-1; j < L; j += prime[i])
unsigned char *x; x[j/8] ^= bitconst[j%8];
FILE *fp;
fp = fopen("k.dat", "wb");
/* prime[0] = 2; prime[1] = 3; the Fth odd prime is prime[F] */ fwrite(x, B, 1, fp);
fclose(fp);
unsigned short *prime; }
prime = (unsigned short *) malloc((F+1) * sizeof(unsigned
short));
unsigned char *c;

86 KAMAWOTAN vol. 1, no. 2, May 2007 College of Arts and Sciences, Ateneo de Naga University 87

You might also like