Skip to content

Instantly share code, notes, and snippets.

@jfbu
jfbu / gist:451cd23300f48f06593ce288b2889d21
Last active September 8, 2018 20:15
CheckWetherBrace
\catcode`@ 11
\long\def\@gobble#1{}
%\long\def\JFB@stop@firstoftwo#1#2{\z@#1}
\long\def\JFB@stop@secondoftwo#1#2{\z@#2}
\long\def\JFB@stop@thirdoffour#1#2#3#4{\z@#3}
\long\def\JFB@CheckWhetherBrace#1{%
\romannumeral
\expandafter\@gobble\expandafter
@jfbu
jfbu / maxbad.py
Last active May 10, 2018 15:39
testing non-uniformity with trunc(R2R1R0 . 0,X1Y1Y0X0) computed with neglect of R0.X0
#!/bin/env/python
"""
This is occupied with finding impact on non-uniformity of evaluating
R times 0,X1Y1Y0X0 in an approximate way which neglects the lowest
order term R0 * X0
Compared to absolute bound 2**(-24) of exact formula near 2**32,
we can not make it much worse because the worst we found is
@jfbu
jfbu / RNGwalkhightbit.output.txt
Created May 7, 2018 07:06
Typical outputs of RNGwalkhighbit.py
>>> test_highbit_tex(12345, 100000, 129)
TeX with seed 12345 and runs of length 129
skipping first 54
{0: 49272, 1: 50728}
TeX: observed probability of more 1s after 100000 batches of 129 is 0.50728
Power_divergenceResult(statistic=21.19936, pvalue=4.1390270194375e-06)
>>> test_highbit_py(82297, 100000, 129)
Python with seed 82297, runs of length 129, 100000 times
{0: 50120, 1: 49880}
Python: observed probability of more 1s after 100000 batches of 129 is 0.4988
@jfbu
jfbu / RNGwalkhighbit.py
Created May 7, 2018 07:04
Comparing \pdfuniformdeviate 2 (i.e. "high bit") and Python's randrange(2) in batches of say 129 draws at a time. TeX's RNG seems to have statistically significantly more often more 1s than 0s.
#!/bin/env/py
"""
Dimanche 06 mai 2018 à 22:18:52
Pour comparaison entre \pdfuniformdeviate 2 et randrange(2)
"""
import random
from scipy.stats import chisquare
@jfbu
jfbu / RNGwalkhighbit-a.out.txt
Created May 6, 2018 14:09
Agains statistics on high bit, with seeds now 8035872 and 10427991. The former seems to indicate again preponderance of 1s in batches of 165 at a time. Not so for latter seed.
Examining batches of 165 bits from \pdfuniformdeviate 2
If more 1s than 0s count 1, else count 0.
There seems to be preponderance of case "more 1s than 0s" in case of seed 08035872,
situation looks more random for 10427991, when averaging over all possible
initial shifts.
+++++++++++++++++++++++
10000 runs of 165 draws
@jfbu
jfbu / RNGwalkhighbit.out.txt
Created May 6, 2018 13:54
Statistics on 165 successive \pdfuniformdeviate 2. It seems they is `>50%` chance of more 1s than 0s, independently of starting point.
HIGH BIT (\pdfuniformdeviate 2)
In successive batches of 165 draws, are there are more 1s than 0s
The answer is Yes on average for all initial shifts and the two
randomly chosen seeds 149847074 and 256844633
(I should have taken the first one < 2**27, too late)
@jfbu
jfbu / RNGwalkhighbit-seed0or1.out.txt
Last active May 6, 2018 13:45
It appears batches of 165 contains more 1s than 0s signifcantly, and the effect is more pronounced for seed = 1.
HIGH BIT SEEDS 0 AND 1
It appears batches of 165 contains more 1s than 0s signifcantly,
and the effect is more pronounced for seed = 1.
It looks more random for batches of 55 and seed = 0, but again
seed = 1 gives more 1s
+++++++++++++++++++++++
10000 runs of 165 draws
@jfbu
jfbu / RNGwalkhighbit.tex
Created May 6, 2018 13:41
Examine random bits from \pdfuniformdeviate 2 in batches of 55s or 165s. See ".out.txt" files.
\newcount\cnta
\newcount\cntb
\newcount\cntc
\newcount\cntd
\newcount\maxrand
\maxrand "10000000
% \the\maxrand
@jfbu
jfbu / RNGwalkwithshift23.tex
Created May 6, 2018 11:04
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
@jfbu
jfbu / RNGwalkwithshift.out.txt
Created May 6, 2018 11:02
Output of RNGwalkwithshift.tex
+++++++++++++++++++++++
10000 runs of 165 draws
+++++++++++++++++++++++
(shift=1, seed=0) 0:4666, 1:5334
(shift=1, seed=1) 0:4723, 1:5277
(shift=2, seed=0) 0:4635, 1:5365
(shift=2, seed=1) 0:4735, 1:5265