McStas logo McStas - A neutron ray-trace simulation package ILL; PSI; ESS Niels Bohr Institute DTU Physics

McStas

About McStas
 Conditions of use
 Authors/Contacts
 Project funding

Download
 Components
 Other Downloads (share)

Mailing list

Search web/mailinglist

Documentation
 Wiki (GitHub)
 McStas manual
 Publications

Links

Report bugs (GitHub)

Code-repository (GitHub)


Random generator

A.2  Random generator

As of McStas 3.x, the default random number generator is a 64-bit adaptation of Marsaglia’s KISS (“Keep It Simple Stupid”) generator, a composite of a linear congruential generator, a xorshift generator, and a multiply-with-carry generator, combined to give a very long period (\(>2^{127}\)) while remaining fast and simple. Crucially, KISS runs identically on both CPU and GPU/OpenACC, which is why it replaced the previously used Mersenne Twister as the default: Mersenne Twister’s large internal state does not parallelize well and is currently not functional for GPU-accelerated simulations (section 3.5.4).

The classic "Mersenne Twister" generator, by Makoto Matsumoto and Takuji Nishimura (see
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html for the original source), remains available as a build-time alternative for CPU-only simulations, selected by compiling the generated instrument with -DRNG_ALG=1 (e.g. via the MCSTAS_CFLAGS environment variable, or mcstas’s C-compiler flag options). It has an extremely large period (\(2^{19937}-1\)) and negligible cross-correlations up to 623 dimensions, but should not be selected for GPU/OpenACC runs.


Last Modified: Tuesday, 06-Oct-2026 21:19:11 CEST
Search website mailinglist archive GitHub repos