Last active
May 6, 2018 11:05
-
-
Save jfbu/cc7dc52420ac499a2127d0c6c0349a5d to your computer and use it in GitHub Desktop.
Count preponderance of 1s in batches of 165, with all possibly initial shifts. Sole exception: shift=23. See RNGwalkwithshift.out.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\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 | |
\def\Dzero{0}% | |
\def\Done{0}% | |
\pdfsetrandomseed #1 | |
% do \foo times a call to \pdfuniformdeviate\maxrand | |
\cnta 0 | |
\xintloop | |
\ifnum\cnta<\foo\space | |
\edef\x{\pdfuniformdeviate \maxrand}% | |
\advance\cnta 1 | |
\repeat | |
% now do #2 times: | |
% examine if more 1s than 0s in next #3 \pdfuniformdeviate \maxrand | |
\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}% | |
} | |
\newwrite\out | |
\immediate\openout\out=\jobname.out | |
% Try with all 55 possible starting point | |
% (the special case "54" makes theoretical analysis a bit easier, | |
% when batches have a length multiple of 55) | |
% We only study runs of 165 draws here. | |
\immediate\write\out{+++++++++++++++++++++++} | |
\immediate\write\out{10000 runs of 165 draws} | |
\immediate\write\out{+++++++++++++++++++++++} | |
\immediate\write\out{} | |
\cntc 1 | |
\xintloop | |
\edef\foo{\the\cntc}% | |
\testwalk {0}{10000}{165}% | |
\testwalk {1}{10000}{165}% | |
\immediate\write\out{}% | |
\ifnum\cntc<55 | |
\advance\cntc 1 | |
\repeat | |
\immediate\write\out{} | |
\immediate\write\out{++++++++++++++++++++++} | |
\immediate\write\out{30000 runs of 55 draws} | |
\immediate\write\out{++++++++++++++++++++++} | |
\immediate\write\out{} | |
\cntc 1 | |
\xintloop | |
\edef\foo{\the\cntc}% | |
\testwalk {0}{30000}{55}% | |
\testwalk {1}{30000}{55}% | |
\immediate\write\out{}% | |
\ifnum\cntc<55 | |
\advance\cntc 1 | |
\repeat | |
\immediate\closeout\out | |
\bye | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment