Skip to content

Instantly share code, notes, and snippets.

@jfbu
Created May 6, 2018 11:04
Show Gist options
  • Save jfbu/55a10499835358a3baf53af010340c5f to your computer and use it in GitHub Desktop.
Save jfbu/55a10499835358a3baf53af010340c5f to your computer and use it in GitHub Desktop.
With initial shift of 22, 23 or 24 do 100000 batches of 165. More 1s than 0s for 22 and 24, more 0s than 1s for 23 (about 5sigma).
\newcount\cnta
\newcount\cntb
\newcount\cntc
\newcount\cntd
\newcount\maxrand
\maxrand "10000000
% \the\maxrand
\input xinttools.sty
\def\testwalk#1#2#3{%
% #1 = seed (O or 1)
% #2 = number of repetitions
% #3 = length of batches; must be an odd integer
\cnta 0
\def\Dzero{0}%
\def\Done{0}%
\pdfsetrandomseed #1
\xintloop
\ifnum\cnta<\foo\space
\edef\x{\pdfuniformdeviate \maxrand}%
\advance\cnta 1
\repeat
\cnta 0
\xintloop {%
\def\S{0}%
\cntb 0
\xintloop
\ifodd\pdfuniformdeviate\maxrand\relax
\edef\S{\the\numexpr\S+1}%
\else
\edef\S{\the\numexpr\S-1}%
\fi
\advance\cntb 1
\ifnum\cntb < #3
\repeat
}\ifnum\S>0
\edef\Done{\the\numexpr\Done+1}%
\else
\edef\Dzero{\the\numexpr\Dzero+1}%
\fi
\advance\cnta 1
\ifnum\cnta < #2
\repeat
\immediate\write\out{(shift=\foo, seed=#1) 0:\Dzero, 1:\Done}%
% \noindent More 0s: \Dzero
% \noindent More 1s: \Done
% Observed probability of more 1s after #2 batches of #3 is
% \the\dimexpr \numexpr\Done*65536/#2 sp\relax
}
\cntc 22
\newwrite\out
\immediate\openout\out=\jobname.out
\xintloop
\edef\foo{\the\cntc}
\testwalk {0}{10000}{165}
\testwalk {1}{10000}{165}
\immediate\write\out{}%
\testwalk {0}{100000}{165}
\testwalk {1}{100000}{165}
\immediate\write\out{}%
\ifnum\cntc<24
\advance\cntc 1
\repeat
\immediate\closeout\out
%\testwalk {0}{30000}{55}
%\testwalk {1}{30000}{55}
\bye
PRODUCES:
(shift=22, seed=0) 0:4767, 1:5233
(shift=22, seed=1) 0:4804, 1:5196
(shift=22, seed=0) 0:47867, 1:52133
(shift=22, seed=1) 0:48020, 1:51980
(shift=23, seed=0) 0:5079, 1:4921
(shift=23, seed=1) 0:5105, 1:4895
(shift=23, seed=0) 0:51074, 1:48926
(shift=23, seed=1) 0:51247, 1:48753
(shift=24, seed=0) 0:4768, 1:5232
(shift=24, seed=1) 0:4762, 1:5238
(shift=24, seed=0) 0:47782, 1:52218
(shift=24, seed=1) 0:48013, 1:51987
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment