Some code
Software for randomized quasi-Monte Carlo and related methods.
Fast scrambled Sobol’ points in R (July 2026)
The original scrambled Sobol’ code (below) was a research tool for people who wanted to run nested uniform scrambling but had trouble finding code that would do it. There was less of that in 2017. I have since asked Claude to optimize that code for speed. It gets a 30 to 50 fold speedup and uses a lot less memory.
The original code also implemented a version of Matousek’s linear matrix
scramble. For a (t,m,s)-net it used Matousek’s scramble on the first
m bits and then pasted IID uniform [0, 2−m)s tails
onto each observation. That is not the same as Matousek’s scramble. The new
code has options nestu, fullmato and
truncmato. Using nestu gets identical results to the
prior code as reported in the comments, and truncmato gets the old
‘mato’. The new option fullmato is tested as described
in the code comments.
The new code has generator matrices for up to 21201 dimensions from Nuyens’ magic point shop embedded in it.
Fast R source code with documentation
Save it to a folder, then in R:
source("rsobol_fast.R")
rsobol(s=10, m=15) # 2^15 Sobol' points in [0,1]^10, nested uniform scramble
rsobol(s=10, m=15, rand=FALSE) # no scrambling
rsobol(s=10, m=15, type="truncmato") # truncated Matousek scrambling as in the original code
rsobol(s=10, m=15, type="fullmato") # usual Matousek scrambling (tested as described in the source)
BibTeX — in published uses, please cite
Kuo and Nuyens (2016) as the source of the generating matrices,
Joe and Kuo (2008) as the source of the underlying direction numbers,
Sobol’ (1967) for the construction, and
this page for the code.
timing script to measure speed on your machine. Speed ratios might be different for you than they were in Claude's virtual machine.
Original scrambled Sobol’ points in R (2017)
Scrambled Sobol’ points are randomized quasi-Monte Carlo (RQMC) points designed for high dimensional integration problems. For background on QMC and RQMC see a practical guide to QMC and references cited therein.
You will need these three files:
- R source code with documentation
- Generating matrices for up to 50 dimensions
- Generating matrices for up to 21201 dimensions
Place them in a directory. From within that directory in R:
source("rsobol.R")
rsobol(m=8, s=5) # n = 2^8 scrambled Sobol' points in s = 5 dimensions, as an n x s matrix
The generating matrices are from Dirk Nuyens’ magic point shop, used with permission gratefully acknowledged. Extra documentation is here.
In published uses, please cite
Kuo and Nuyens (2016) as the source of the generating matrices,
Joe and Kuo (2008) as the source of the underlying direction numbers,
and Sobol’ (1967) for the underlying construction.
The randomization is from Owen (1995). Also included is the randomization from Matousek (1998).
Matousek’s algorithm requires less space but it is widely implemented elsewhere. Computer memory is more abundant now than in the 1990s, so saving space is less critical. This code actually re-reads the generating matrices from disk each time a net is constructed. There are faster ways to generate them, but this code is fast enough for research use.
Caveat: the Matousek scrambling code only uses that randomization for the first m bits when there are 2m points to generate. It pastes a uniform random tail onto subsequent bits. It also generates an error for 2 points (i.e., m = 1). For that one can take the first 2 points from m = 2.
Sobol’ movies
Some mp4s showing pairwise projections of the first 30 Sobol’ variables. They roll at one projection per second, so they are designed to take 7 minutes 15 seconds.
- m = 7, n = 128 2.1 Mb
- m = 9, n = 512 7.0 Mb
- m = 11, n = 2048 24 Mb
- m = 13, n = 4096 41 Mb
- m = 15, n = 32768 255 Mb
Other code
- Python for RQMC survey paper
- Randomized Halton algorithm in R (PDF) | the R code
- Scalable crossed mixed effects — Python code on GitHub, by Katelyn Gao.
- Empirical likelihood — some R code and pointers to other code.
- R code to find the optimal thinning factors for MCMC with AR(1) covariances