a binary sequence generator based on the kolakoski sequence and multiples of odd primes

5
KAMAWOTAN vol. 1, no. 2, May 2007 78 Secondary Sources Bernasconi, R. (1987). Deconstruction and the possibility of ethics. In J. Sallis (Ed.), Deconstruction and philosophy. Chicago: University of Chicago Press. Caputo, J. (1993a). Against ethics: Contributions to a poetics of obligation with constant reference to deconstruction, Studies in Continental Thought. Bloomington: Indiana University Press. Caputo, J. (1993b). Radical hermeneutics: Repetition, deconstruction and the hermeneutic project, Studies in Phenomenology and Existential Philosophy. Bloomington: Indiana University Press. Caputo, J. (1997a). Deconstruction in a nutshell. New York: Fordham University Press. Caputo, J. (1997b). The prayers and tears of Jacques Derrida: Religion without religion. Indianapolis: Indiana University Press. Cornell, D. (Ed.). (1992). Deconstruction and the possibility of justice. New York: Routledge. Critchley, S. (1990). Derrida and deconstruction. In R. Kearney (Ed.), Routledge history of philosophy (vol. VII). London and New York: Routledge. Critchley, S. (1992). The ethics of deconstruction: Derrida and Levinas. Oxford: Blackwell. Culler, J. (1983). On deconstruction. London: Routledge and Kegan Paul. Kearney, R. (1999). Poetics of modernity. New York: Humanity Books. Levinas, E. (1969). Totality and infinity. (A. Lingis, Trans.). Pittsburgh: Duquesne University Press. Norris, C. (1987). Derrida. Cambridge: Harvard University Press. Rapaport, H. (2003). Later Derrida. New York: Routledge. Sim, S. (1992). Beyond aesthetics. London: Harvester Wheatsheaf. College of Arts and Sciences, Ateneo de Naga University 79 A Binary Sequence Generator Based on the Kolakoski Sequence and Multiples of Odd Primes Joel R. Noche Department of Mathematics and Natural Sciences Abstract An earlier binary sequence generator is modified to yield better performance in the DIEHARD tests for randomness of uniformly distributed numbers. The new generator inverts every p bits of a modified Kolakoski sequence, where p is a prime number, and does this for the first f odd prime numbers. Samples from the resulting binary sequence can be used in scientific applications requiring random numbers. Introduction Large amounts of “random” numbers are currently needed by many applications (Hayes, 2001). In this work, numbers are said to be random if they perform well in commonly accepted statistical tests of randomness. Pseudo-random number generators (PRNGs) usually refer to generators of uniformly distributed numbers (often over the interval (0,1)). (Arbitrary distributions are usually generated by applying transformations to these values.) PRNGs differ from (true) random number generators (RNGs) in that the former perform deterministic operations on a seed value, while the latter rely on a non-deterministic source of randomness (usually a physical process such as radioactive decay or thermal noise). Two (of many) 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 (2) the sequence should not repeat, that is, it should be non-periodic. 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

Upload: joel-reyes-noche

Post on 17-Nov-2014

266 views

Category:

Documents


4 download

DESCRIPTION

Kamawotan, vol. 1, no. 2, May 2007, pp. 79-87.

TRANSCRIPT

Page 1: A Binary Sequence Generator Based on the Kolakoski Sequence and Multiples of Odd Primes

KA

MA

WO

TA

N v

ol.

1,

no. 2

, M

ay

20

07

78

Sec

on

dary

So

urce

s

Ber

nasc

oni,

R.

(198

7).

De

cons

truc

tion

and

the

pos

sibi

lity

of e

thic

s. I

n J.

S

alli

s (E

d.),

Dec

ons

truc

tion

an

d p

hilo

sop

hy

. C

hica

go:

Uni

vers

ity o

f C

hica

go P

ress

.

Ca

puto

, J.

(19

93a

). Ag

ains

t e

thic

s: C

on

trib

utio

ns t

o a

po

etic

s of

ob

liga

tion

with

con

sta

nt r

efe

ren

ce t

o d

eco

nstr

uct

ion

, S

tudi

es i

n C

ontin

enta

l T

hou

ght.

Blo

omin

gton

: In

dia

na U

nive

rsity

Pre

ss.

Ca

puto

, J.

(19

93b)

. Ra

dica

l he

rme

neu

tics:

Re

petit

ion

, de

con

stru

ctio

n a

nd

the

her

me

neu

tic p

roje

ct, S

tudi

es in

Phe

nom

enol

ogy

and

Exi

sten

tial

Phi

loso

phy.

Blo

omin

gton

: In

dia

na U

nive

rsity

Pre

ss.

Ca

puto

, J.

(1

997a

). De

con

stru

ctio

n

in

a

nut

shel

l.

New

Y

ork:

F

ordh

am

Uni

vers

ity P

ress

.

Ca

puto

, J.

(19

97b)

. Th

e p

raye

rs a

nd

te

ars

of J

acq

ues

De

rrid

a:

Rel

igio

n w

itho

ut r

elig

ion.

Ind

iana

polis

: Ind

iana

Uni

vers

ity P

ress

.

Cor

nell,

D.

(Ed.

). (

1992

). De

cons

tru

ctio

n a

nd t

he

pos

sib

ility

of

just

ice

. N

ew

Yor

k: R

outle

dge.

Cri

tchl

ey,

S.

(199

0).

Der

rida

a

nd

deco

nstr

uctio

n.

In

R.

Kea

rne

y (E

d.),

R

ou

tledg

e h

isto

ry o

f p

hilo

sop

hy (vo

l. V

II).

Lond

on a

nd N

ew Y

ork:

R

outle

dge.

Cri

tchl

ey,

S.

(199

2). T

he e

thic

s of

de

con

stru

ctio

n: D

errid

a a

nd

Lev

ina

s.

Oxf

ord:

Bla

ckw

ell.

Cul

ler,

J. (

1983

). On

dec

ons

truc

tion. L

ondo

n: R

outle

dge

and

Keg

an

Pa

ul.

Kea

rne

y, R

. (19

99).

Po

etic

s of

mo

der

nity. N

ew Y

ork:

Hum

anity

Boo

ks.

Levi

nas,

E.

(196

9). T

ota

lity

and

inf

inity

. (A

. Li

ngis

, T

rans

.).

Pitt

sbur

gh:

Duq

uesn

e U

nive

rsity

Pre

ss.

Nor

ris, C

. (1

987)

. De

rrid

a. C

am

brid

ge:

Ha

rva

rd U

nive

rsity

Pre

ss.

Ra

papo

rt,

H. (

2003

). La

ter

Der

rida.

New

Yor

k: R

outle

dge.

Sim

, S. (

1992

). Bey

on

d a

esth

etic

s. Lon

don:

Ha

rves

ter

Whe

ats

hea

f.

Col

lege

of

Art

s a

nd

Sci

en

ces,

Ate

neo

de

Na

ga

Un

ive

rsi

ty

79

A B

inar

y S

eque

nce

Gen

erat

or B

ased

on

the

Kol

akos

ki S

eque

nce

and

Mu

ltip

les

of O

dd

Pri

mes

Joel

R. N

oche

D

epa

rtm

ent

of M

ath

em

atic

s a

nd N

atur

al S

cien

ces

A

bstr

act

An

ear

lier

bin

ary

seq

uen

ce g

ene

rato

r is

mo

difi

ed

to

yie

ld

be

tter

per

form

an

ce i

n t

he D

IEH

AR

D t

ests

for

ran

dom

ne

ss

of

un

iform

ly

dis

trib

ute

d

num

ber

s.

T

he

n

ew

g

ene

rato

r in

vert

s e

very

p

bits

of

a

mo

difi

ed

K

ola

kosk

i se

qu

ence

, w

he

re p

is a

prim

e n

um

ber

, a

nd d

oes

this

for

the

fi

rst f

od

d p

rim

e

num

ber

s.

S

amp

les

from

th

e

resu

ltin

g

bina

ry

sequ

enc

e c

an

be

use

d i

n s

cie

ntifi

c a

ppl

ica

tions

re

qui

rin

g ra

nd

om n

umbe

rs.

Intr

oduc

tion

Larg

e a

mo

unt

s of

“ra

ndo

m”

num

ber

s ar

e cu

rren

tly n

eed

ed

by

ma

ny

ap

plic

atio

ns (

Hay

es,

20

01)

. I

n th

is w

ork,

num

ber

s a

re s

aid

to

be

rand

om

if t

hey

perf

orm

wel

l in

com

mo

nly

acc

ept

ed

sta

tistic

al t

ests

of

ra

nd

om

nes

s.

Pse

ud

o-ra

ndo

m n

um

ber

ge

nera

tors

(P

RN

Gs)

usu

ally

re

fer

to g

ene

rato

rs o

f u

nifo

rmly

dis

trib

uted

nu

mb

ers

(oft

en o

ver

the

in

terv

al

(0,1

)).

(A

rbitr

ary

dist

rib

utio

ns

are

us

ually ge

nera

ted

by

app

lyin

g tr

ans

form

atio

ns t

o th

ese

valu

es.)

P

RN

Gs

diffe

r fr

om

(tr

ue)

rand

om

n

um

ber

g

ener

ato

rs

(RN

Gs)

in

th

at

the

form

er

per

form

de

term

inis

tic o

per

atio

ns o

n a

see

d va

lue,

whi

le t

he l

att

er r

ely

on a

n

on-d

eter

min

istic

so

urce

of

rand

om

nes

s (u

sua

lly a

phy

sica

l pr

oces

s su

ch

as

radi

oact

ive

deca

y or

th

erm

al

noi

se).

Tw

o (o

f m

any

) pr

ope

rtie

s th

at

a “

goo

d” P

RN

G o

r R

NG

sho

uld

have

are

: (

1)

the

num

ber

s of

bits

‘0’

and

‘1

’ it

prod

uces

sh

ould

be

alm

ost

eq

ual,

and

(2

) th

e se

que

nce

sho

uld

not

rep

eat,

tha

t is,

it s

houl

d b

e n

on-

peri

odic

.

In a

n ea

rlie

r w

ork

(Noc

he,

20

04)

, a

cer

tain

bin

ary

se

que

nce

ge

nera

tor

wa

s pr

opos

ed.

It

star

ted

with

a T

hu

e-M

orse

seq

uenc

e 0

, 1

, 1

, 0

, 1

, 0

, 0,

1,

1, 0

, 0

, 1,

0,

1, 1

, 0

, …

(se

que

nce

A01

00

60

in S

loa

ne

(2

006

)).

Thi

s se

que

nce

is n

ot p

erio

dic

(Allo

uch

e &

Sh

alli

t, 1

99

9) a

nd

the

nu

mb

ers

of ‘

0’s

and

‘1

’s i

n a

n in

finite

Th

ue-M

orse

se

que

nce

are

th

e sa

me.

T

his

seq

uenc

e, h

ow

eve

r, t

erri

bly

fa

ils c

om

mo

nly

acc

ept

ed

st

atis

tica

l tes

ts o

f ra

ndo

mn

ess.

It w

as s

how

n in

(N

och

e, 2

00

4) th

at

the

alg

orith

m u

sed

in t

hat

wor

k to

ge

nera

te t

he T

hue

-Mor

se s

eque

nce

lea

d to

an

int

eres

ting

Page 2: A Binary Sequence Generator Based on the Kolakoski Sequence and Multiples of Odd Primes

KA

MA

WO

TA

N v

ol.

1,

no. 2

, M

ay

20

07

80

met

hod

of

ad

din

g “d

isor

der”

to

the

orig

ina

l seq

ue

nce

. T

he b

its w

hos

e

orde

r in

th

e se

qu

enc

e w

as

a m

ultip

le o

f a

pri

me

nu

mb

er p

wer

e in

vert

ed,

an

d th

is w

as d

one

seq

uen

tially

for

incr

easi

ng

p fo

r th

e fir

st f

odd

pri

me

nu

mb

ers.

(O

dd p

rim

e n

um

ber

s w

ere

chos

en b

eca

use

no

“dis

orde

r” i

s in

trod

uce

d b

y in

vert

ing

all

the

eve

n b

its,

tha

t is

, th

e m

ultip

les

of t

he o

nly

eve

n pr

ime

nu

mb

er,

2.)

Thi

s ge

nera

tor

is

now

m

odifi

ed

by

sta

rtin

g it

with

a

K

ola

kosk

i seq

uenc

e in

stea

d.

A K

ola

kosk

i seq

uen

ce is

a

seq

uenc

e th

at

equa

ls it

s ow

n ru

n le

ngt

h se

que

nce

(K

ola

kosk

i, 1

96

5).

T

he s

eque

nce

()

{}∞ =0n

nk

= 1

, 2,

2,

1, 1

, 2,

1,

2, 2

, 1,

2,

2, 1

, 1,

2,

… (

sequ

en

ce

A0

00

002

in S

loa

ne (

20

06

)) is

the

Kol

ako

ski s

equ

enc

e t

hat

star

ts w

ith

‘1.’

Lis

ted

abo

ve a

re it

s fir

st t

en r

uns;

the

fir

st r

un is

‘1,’

the

seco

nd

run

is ‘2

,2,’

the

thir

d ru

n is

‘1,1

,’ th

e fo

urth

ru

n is

‘2,’

and

so

on.

T

he

fir

st r

un h

as k

(1)

= 1

ele

me

nt,

the

seco

nd

run

has

k(2)

= 2

ele

men

ts,

the

thir

d ru

n ha

s k(3

) =

2 e

lem

ent

s, t

he f

ourt

h ru

n h

as k(4)

= 1

el

em

ent

, a

nd s

o o

n.

The

Kol

ako

ski

seq

uenc

e th

at

star

ts w

ith ‘2

’ is

2,

2, 1

, 1

, 2

, 1

, 2

, 2

, 1

, 2

, 2,

1,

1, 2

, 1,

1,

… (

seq

uenc

e A

07

888

0 i

n S

loa

ne

(20

06))

.

Thi

s is

the

ver

sio

n a

rbitr

arily

cho

sen

in t

his

wor

k.

A b

ina

ry s

eque

nce

co

mp

ose

d of

‘0

’s

and

‘1

’s

is

desi

red,

so

the

‘2’

s a

re a

rbi

trar

ily

conv

erte

d in

to ‘0

’s t

o g

et th

e b

ina

ry s

eque

nce (

){

}∞ =0nn

x =

0,

0,

1, 1

, 0,

1,

0, 0

, 1

, 0,

0,

1, 1

, 0,

1,

1, …

.

The

K

ola

kosk

i se

que

nce

is

not

peri

odic

(K

ola

kosk

i a

nd

Uco

luk,

19

66

) a

nd i

t is

co

njec

ture

d (b

ut n

ot y

et p

ro

ven)

tha

t th

e

num

ber

of

‘0’s

and

‘1

’s i

n an

inf

inite

Kol

ako

ski

seq

uen

ce a

re t

he

sa

me

(Wei

sste

in, 2

00

6).

Met

hodo

logy

One

pop

ula

r w

ay

to t

est

PR

NG

s a

nd R

NG

s is

the

DIE

HA

RD

se

ries

of t

ests

(M

ars

agl

ia,

199

5).

DIE

HA

RD

co

ntai

ns fi

fte

en

test

s fo

r ra

ndo

mn

ess

of u

nifo

rmly

dis

trib

uted

nu

mb

ers.

C

are

sho

uld

be

take

n

whe

n ru

nni

ng

thes

e te

sts.

F

or e

xam

ple,

Mar

sagl

ia r

epor

ts t

hat

the

hard

wa

re

RN

Gs

he

test

ed

faile

d “s

pect

acu

larl

y.”

D

avi

es

(19

97)

fo

un

d th

at

the

sup

pose

d fa

ilure

s w

ere

mos

tly d

ue

to a

da

ta h

an

dlin

g

erro

r:

each

byt

e w

ith a

va

lue

of 1

0 w

as

bei

ng r

ecor

de

d a

s tw

o b

ytes

w

ith v

alu

es o

f 13

and

10

(a

car

ria

ge r

etur

n fo

llow

ed b

y a

lin

e fe

ed)

.

An

othe

r po

ssib

le p

rob

lem

is t

he d

iffer

ent

con

vent

ions

fo

r th

e or

der

in

whi

ch t

he

bits

or

byt

es a

re s

tore

d in

a w

ord.

T

he

rea

rra

nge

me

nt o

f b

ytes

whe

n c

op

yin

g b

etw

een

com

put

ers

with

diff

eren

t c

on

vent

ions

Col

lege

of

Art

s a

nd

Sci

en

ces,

Ate

neo

de

Na

ga

Un

ive

rsi

ty

81

can

affe

ct t

he r

esul

ts o

f co

rrel

atio

ns t

ests

an

d ot

her

test

s (D

avie

s,

200

0).

In

thi

s w

ork,

bot

h pr

oble

ms

are

avo

ide

d:

the

out

put

is

save

d

as

a b

inar

y fil

e (n

ot a

tex

t fil

e),

and

onl

y b

yte-

siz

ed w

ord

s ar

e us

ed

to

repr

esen

t th

e se

qu

ence

. D

eta

ils o

f th

e te

sts

an

d th

e

ass

ocia

ted p

-va

lues

are

in

Ma

rsa

glia

(1

99

5).

The

res

ults

of

the

test

s ca

n b

e

sum

ma

rize

d b

y 1

46

p-

valu

es.

The

pro

gra

m p

rese

nte

d in

(N

och

e, 2

00

4)

calle

d su

bro

utin

es

fro

m in

side

loo

ps.

Th

e re

vise

d ve

rsio

n lis

ted

in A

ppe

ndi

x A

doe

s n

ot

use

sub

rout

ine

calls

, res

ultin

g in

impr

ove

d p

erfo

rma

nce

.

Fo

ur c

ase

s a

re t

este

d:

thos

e in

volv

ing

the

first

f

= 1

0,

10

0,

100

0,

and

20

00

odd

pri

me

nu

mb

ers.

T

he

case

s la

bele

d t

10

, t1

00

, t1

00

0, a

nd t

20

00 u

se t

he T

hu

e-M

orse

seq

uenc

e, a

nd

tho

se l

ab

eled

k1

0,

k10

0,

k10

00

, a

nd k

20

00

use

the

Kol

ako

ski s

eque

nc

e.

(The

latt

er

four

ca

ses

use

the

pro

gra

m l

iste

d in

Ap

pen

dix

B.)

E

ach

seq

ue

nce

is

16,

77

7,2

16

byte

s lo

ng.

(D

IEH

AR

D n

eeds

at

lea

st a

n 8

0 m

illio

n b

it lo

ng te

st s

eque

nce

for

all

of it

s te

sts

to r

un.)

For

co

mpa

riso

n, t

he r

esul

ts o

f th

e P

RN

G K

ISS

(M

arsa

gli

a,

199

5)

are

also

inc

lud

ed.

It

“se

ems

to p

ass

all

[the

DIE

HA

RD

] te

sts

and

is

hig

hly

reco

mm

en

ded

for

sp

eed

and

sim

plic

ity”

(Mar

sagl

ia,

199

5).

T

he

KIS

S s

equ

enc

e te

ste

d h

ere

is 1

1,4

68,

80

0 b

yte

s lo

ng a

nd

use

d th

e se

ed

inte

gers

1,

4, 3

, a

nd 4

4.

Res

ults

Ta

ble

1 s

how

s th

e ru

n tim

es f

or a

co

mp

uter

with

an

Int

el

Cel

eron

1.7

0 G

Hz

proc

esso

r, 2

56

MB

of

RA

M,

and

a M

icr

osof

t W

ind

ows

XP

ope

ratin

g sy

ste

m.

The

KIS

S o

utpu

t fil

e ta

kes

less

tha

n

a s

econ

d to

ge

nera

te a

fter

the

seed

va

lues

are

giv

en.

Ta

ble

1. R

un ti

mes

(in

sec

onds

)

f T

hue-

Mor

se

(Noc

he,

20

04)

T

hue

-Mor

se

(App

endi

x A

) K

ola

kosk

i (A

ppen

dix

B)

10

1

3

4 8

1

00

18

7

11

1

00

0 2

6

15

1

8

20

00

29

1

6

20

The

p-v

alu

es f

or t

he t

10

, t1

00,

t1

000

, t2

00

0,

and

KIS

S t

est

ca

ses

are

lis

ted

in (

Noc

he,

20

04

).

(Th

e pr

ogr

am

in

Ap

pen

dix

A

yiel

ds t

he s

am

e D

IEH

AR

D

p-va

lues

as

the

pro

gra

m in

Noc

he

(20

04).

)

Page 3: A Binary Sequence Generator Based on the Kolakoski Sequence and Multiples of Odd Primes

KA

MA

WO

TA

N v

ol.

1,

no. 2

, M

ay

20

07

82

Due

to

spa

ce l

imita

tions

, th

e p-va

lues

for

the

k1

0,

k10

0,

k10

00

, an

d

k20

00

ca

ses

are

not

liste

d he

re.

Dis

cuss

ion

It i

s im

plie

d t

hat

if a

ll th

e p-

valu

es o

f a

seq

ue

nce

tes

ted

by

DIE

HA

RD

lie

in t

he r

ang

e (0

.025

, 0.

97

5) t

hen

the

seq

uen

ce is

sa

id t

o ha

ve p

ass

ed a

ll th

e D

IEH

AR

D t

ests

. T

his

is t

he r

easo

ning

be

hin

d th

e

cla

im in

(N

oche

, 20

04

) th

at

the

seq

uen

ce t

20

00

per

form

ed

wel

l in

the

te

sts.

A

sub

seq

uent

ana

lysi

s of

the

da

ta,

how

eve

r, s

how

s th

at

t20

00’

s te

st r

esul

ts s

till l

eave

mor

e to

be

desi

red.

The

his

togr

am

s of

the

p-va

lues

for

ea

ch T

hue

-Mor

se-b

ased

te

st c

ase

are

sho

wn

in F

igur

e 1

. N

ote

tha

t m

ost

of t

he p

-va

lues

are

in

the

upp

erm

ost

deci

le.

The

his

togr

am

for

the

KIS

S t

est

ca

se (

Fig

ure

2)

is m

ore

uni

form

ly d

istr

ibut

ed.

Thi

s se

em

s to

im

ply

tha

t a

“m

ore

ra

ndo

m”

seq

ue

nce

wo

uld

have

a m

ore

uni

form

ly d

istr

ibu

ted

set

of p-

valu

es in

the

DIE

HA

RD

test

s.

Fig

ure

1.

His

togr

am

s of

DIE

HA

RD

p-va

lues

(T

hue-

Mor

se-b

ase

d se

quen

ces)

0.0-

0.1

0.1

-0.2

0.2-

0.3

0.3-

0.4

0.4

-0.5

0.5

-0.6

0.6

-0.7

0.7

-0.8

0.8-

0.9

0.9

-1.0

t200

0

t100

0

t100t1

00

20406080

100

120

140

Col

lege

of

Art

s a

nd

Sci

en

ces,

Ate

neo

de

Na

ga

Un

ive

rsi

ty

83

Fig

ure

2.

His

togr

am

of D

IEH

AR

D p-

valu

es (

KIS

S s

eque

nce

)

0.0-

0.1

0.1-

0.2

0.2-

0.3

0.3-

0.4

0.4-

0.5

0.5-

0.6

0.6-

0.7

0.7-

0.8

0.8-

0.9

0.9-

1.0

KIS

S

0

20406080

100

120

140

Fig

ure

3.

His

togr

am

s of

DIE

HA

RD

p-va

lues

(K

ola

kosk

i-ba

sed

sequ

ence

s)

0.0-

0.1

0.1-

0.2

0.2

-0.3

0.3

-0.4

0.4-

0.5

0.5

-0.6

0.6-

0.7

0.7

-0.8

0.8-

0.9

0.9

-1.0

k200

0

k100

0

k10

0

k10

0

20406080

100

120

140

Page 4: A Binary Sequence Generator Based on the Kolakoski Sequence and Multiples of Odd Primes

KA

MA

WO

TA

N v

ol.

1,

no. 2

, M

ay

20

07

84

Fig

ure

3 s

how

s th

e hi

stog

ram

s fo

r th

e K

ola

kosk

i-ba

sed

test

ca

ses.

It

show

s th

at e

ven

case

k1

00

see

ms

to h

ave

be

tter

te

st r

esul

ts

tha

n ca

se t

20

00.

It m

ust

be

me

ntio

ned,

how

eve

r, t

hat

all

the

Kol

ako

ski

-bas

ed

test

ca

ses

perf

orm

ed

very

p

oor

ly

in

the

se

vent

h D

IEH

AR

D

test

(“

Cou

nt t

he 1

’s in

a s

trea

m o

f b

ytes

”).

Thi

s ca

n b

e s

een

in T

ab

le 2

.

Ta

ble

2. p

-va

lue

s fo

r th

e se

vent

h D

IEH

AR

D te

st (

roun

ded

off)

.

t1

0 t1

00

t100

0 t2

000

K

ISS

k1

0 k1

00

k100

0 k2

000

p 109

1

.000

0.

979

0.96

3 0.

997

0.9

19

1.00

0 1.

000

1.00

0 0.

993

p 110

1

.000

1.

000

1.00

0 0.

835

0.3

36

1.00

0 1.

000

1.00

0 1.

000

Con

clus

ions

The

bin

ary

seq

uenc

e ge

ner

ato

r pr

esen

ted

her

e is

sh

own

to

pe

rfor

m a

rgua

bly

bet

ter

in a

pop

ular

set

of

test

s fo

r r

and

om

nes

s th

an

a

n ea

rlie

r w

ork.

In

pa

rtic

ula

r, c

ase

k1

00 h

as

a s

hor

ter

run

tim

e th

an

ca

se t

20

00

and

its

p-

valu

es a

re m

ore

uni

form

ly d

istr

ibut

ed

tha

n th

ose

of

ca

se t

20

00.

Ref

eren

ces

Allo

uche

, J.

-P.,

& S

halli

t, J.

(19

99).

The

ubi

quitous

Pro

uhet

-Thu

e-M

orse

se

quen

ce.

In Se

que

nce

s a

nd T

heir

A

ppl

ica

tions

: P

roce

edin

gs of

S

ET

A ’9

8, S

prin

ger-

Ver

lag,

1–1

6.

Da

vies

, R

. (1

997)

. Tru

e r

an

dom

num

ber

ge

nera

tors. R

etri

eved

Apr

il 20

04,

from

http

://w

ww

.rob

ertn

z. n

et/tr

ue_m

g.ht

ml

Da

vies

, R

. (2

000)

. Ha

rdw

are

ran

dom

num

ber

gen

erat

ors

. R

etrie

ved

Apr

il 20

04, f

rom

http

://w

ww

.rob

ertn

z.ne

t/hw

rng.

htm

l

Ha

yes,

B.

(200

1).

Com

putin

g sc

ienc

e: R

ando

mne

ss a

s a

res

ourc

e, A

mer

ica

n S

cie

ntis

t, 89(

4), 3

00–3

04.

Kol

ako

ski,

W.

(196

5).

Sel

f ge

nera

ting

runs

, P

robl

em 53

04.

Am

eric

an

Ma

the

ma

tical

Mo

nth

ly, 7

2(6)

, 674

.

Kol

ako

ski,

W.,

&

Uco

luk,

N

. (1

966)

. 53

04. A

me

rican

M

ath

em

atic

al

Mo

nth

ly, 7

3(6)

, 68

1–68

2.

Mar

sagl

ia,

G.

(199

5). The

Mar

sag

lia r

an

dom

num

ber

CD

RO

M in

clu

din

g t

he

DIE

HA

RD

bat

tery

of

test

s of

ra

ndom

ness

. R

etrie

ved

Ma

rch

2004

, fr

om h

ttp://

sta

t.fsu

.edu

/pub

/die

hard

/

Noc

he,

J. (

2004

). A

bin

ary

seq

uenc

e ge

nera

tor

base

d o

n th

e T

hue-

Mor

se

sequ

ence

a

nd

mul

tiple

s of

pr

imes

. T

he

Ph

ilipp

ine

S

tatis

ticia

n, 5

3(1–

4),

67–7

6.

Col

lege

of

Art

s a

nd

Sci

en

ces,

Ate

neo

de

Na

ga

Un

ive

rsi

ty

85

Slo

ane

, N

. (2

006)

. Th

e o

n-li

ne e

ncyc

lope

dia

of

inte

ger

sequ

en

ces

. R

etri

eved

A

pril

2007

, fr

om h

ttp:

//ww

w.r

esea

rch.

att.c

om/~

njas

/se

quen

ces/

Wei

sste

in,

E.

(200

6). K

olak

oski

se

que

nce. F

rom

Ma

thW

orld

—A

Wo

lfra

m

We

b

Re

sour

ce. R

etrie

ved

Apr

il 20

07

from

ht

tp://

ma

thw

orld

.w

olfr

am

.com

/Kol

ako

skiS

eque

nce.

htm

l

App

endi

x A

/* improved version of the program presented in (Noche, 2004) */

/* source code for Microsoft Visual C++ 6.0 */

#include <stdio.h>

#include <stdlib.h>

#define M 27

#define L 134217728

#define B 16777216

#define F 2000

#define MAXPRIME 17393

/* F=10, MAXPRIME=31

F=100, MAXPRIME=547

F=1000, MAXPRIME=7927

F=2000, MAXPRIME=17393 */

void main(void)

{

unsigned char bitconst[8] =

{0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};

unsigned long j = 0, k;

unsigned short i;

unsigned char *x;

FILE *fp;

unsigned short *prime;

prime = (unsigned short *) malloc((F+1) * sizeof(unsigned

short));

unsigned char *c;

c = (unsigned char *) malloc((MAXPRIME+1) * sizeof(unsigned

char));

for (i = 1; i <= MAXPRIME; i++)

c[i] = 1;

c[1] = 0;

prime[0] = 2;

do

{

for (i = prime[j]; i <= MAXPRIME; i += prime[j])

c[i] = 0;

i = prime[j] + 1;

while (c[i] == 0)

i++;

prime[++j] = i;

}

while (j < F);

free(c);

Page 5: A Binary Sequence Generator Based on the Kolakoski Sequence and Multiples of Odd Primes

KA

MA

WO

TA

N v

ol.

1,

no. 2

, M

ay

20

07

86

x = (unsigned char *) malloc(B * sizeof(unsigned char));

x[0] = 0x69;

x[1] = ~x[0];

for (i = 1; i < (M-3); i++)

{

k = 1 << i; /* k = 2^i */

for (j = 0; j < k; j++)

x[k+j] = ~x[j];

}

for (i = 1; i <= F; i++)

for (j = prime[i]-1; j < L; j += prime[i])

x[j/8] ^= bitconst[j%8];

fp = fopen("t.dat", "wb");

fwrite(x, B, 1, fp);

fclose(fp);

}

App

endi

x B

/* source code for Microsoft Visual C++ 6.0 */

#include <stdio.h>

#include <stdlib.h>

#define M 27

#define L 134217728

#define B 16777216

#define F 2000

#define MAXPRIME 17393

/* F=10, MAXPRIME=31

F=100, MAXPRIME=547

F=1000, MAXPRIME=7927

F=2000, MAXPRIME=17393

L is the length of the sequence in bits; L = 2^M

B is the size of the sequence in bytes

F is the number of (odd) primes to use

MAXPRIME is the Fth odd prime (the (F+1)th prime) */

void main(void)

{

unsigned char bitconst[8] =

{0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};

unsigned long j = 0, k;

unsigned short i;

unsigned char *x;

FILE *fp;

/* prime[0] = 2; prime[1] = 3; the Fth odd prime is prime[F] */

unsigned short *prime;

prime = (unsigned short *) malloc((F+1) * sizeof(unsigned

short));

unsigned char *c;

Col

lege

of

Art

s a

nd

Sci

en

ces,

Ate

neo

de

Na

ga

Un

ive

rsi

ty

87

c = (unsigned char *) malloc((MAXPRIME+1) * sizeof(unsigned

char));

/* data types might need to be changed if F is increased */

for (i = 1; i <= MAXPRIME; i++)

c[i] = 1;

c[1] = 0;

prime[0] = 2;

do

{

for (i = prime[j]; i <= MAXPRIME; i += prime[j])

c[i] = 0;

i = prime[j] + 1;

while (c[i] == 0)

i++;

prime[++j] = i;

}

while (j < F);

free(c);

/* create Kolakoski word */

x = (unsigned char *) malloc(B * sizeof(unsigned char));

x[0] = 0x34;

for (j = 1; j < B; j++)

x[j] = 0x00;

k = 8;

for (j = 5; k < L; j++)

{

x[k/8] |= bitconst[k%8];

k++;

if ((x[j/8] & bitconst[j%8]) == 0x00)

{

x[k/8] |= bitconst[k%8];

k++;

}

j++;

k++;

if ((x[j/8] & bitconst[j%8]) == 0x00)

k++;

}

/* invert bits that are multiples of the first F odd primes */

for (i = 1; i <= F; i++)

for (j = prime[i]-1; j < L; j += prime[i])

x[j/8] ^= bitconst[j%8];

fp = fopen("k.dat", "wb");

fwrite(x, B, 1, fp);

fclose(fp);

}