Skip to content

Instantly share code, notes, and snippets.

@rkern
rkern / TorchDataLoaderPRNG.ipynb
Created July 11, 2023 01:08
Demonstrate successful worker_init_fn usage to seed the np.random PRNG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rkern
rkern / WHSmoothing.ipynb
Created September 4, 2022 00:51
Whittaker-Henderson Smoothing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rkern
rkern / Histogram-Fitting.ipynb
Last active April 3, 2022 04:08
Notebook comparing MLE-fitting of histograms with ad hoc curve-fitting of histograms
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rkern
rkern / Z3PRNG.ipynb
Created October 23, 2021 18:07
Notebook demonstrating the use of Z3 to try to solve for the state of PCG PRNGs
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rkern
rkern / nbcat.py
Created April 14, 2021 18:25
Page Jupyter notebooks on the terminal
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Page Jupyter notebooks on the terminal.
Can be used to search with ripgrep:
$ rg --pre nbcat --pre-glob "*.ipynb" <search_term>
To the extent possible under law, Robert Kern has waived all copyright
@rkern
rkern / pcg64_correlations.py
Last active June 4, 2020 21:04
Verifying numpy#16313
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import sys
import numpy as np
from numpy.random import PCG64
@rkern
rkern / seed_seq.py
Last active August 14, 2020 03:09
Python implementation of SeedSequence
#!/usr/bin/env python
""" PRNG seed sequence implementation for np.random.
The algorithms are derived from Melissa E. O'Neill's C++11 `std::seed_seq`
implementation, as it has a lot of nice properties that we want.
https://gist.github.com/imneme/540829265469e673d045
http://www.pcg-random.org/posts/developing-a-seed_seq-alternative.html
The MIT License (MIT)
@rkern
rkern / pcg_streams.py
Last active June 12, 2019 08:09
PractRand driver for testing interleaved PCG32 streams
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import secrets
import sys
import numpy as np
from numpy.random import PCG32
@rkern
rkern / test_fuzzed_histogram.py
Created May 24, 2016 10:18
Fuzz test for histogram consistency.
import numpy as np
class BaseHistogramAccuracy(object):
# The number of fuzz tests to perform.
n_fuzz = 1000
# The PRNG seed to use.
seed = 8675309