RANLUX is a subtract-and-borrow random number generator proposed by Marsaglia and Zaman, implemented by F. James with the name RCARRY in 1991, and later improved by Martin Lüscher in 1993 to produce “Luxury Pseudo-Random Numbers”. The FORTRAN 77 version was written by F. James. The algorithm is suitable for Monte Carlo simulations or other calculations requiring a uniform pseudo-random generator.
One can choose between five luxury levels (table 1). The default level is 3.
Level | Description |
---|---|
0 | Equivalent to the original RCARRY of Marsaglia and Zaman, very long period, but fails many tests. |
1 | Considerable improvement in quality over level 0, passes gap test, but fails spectral test. |
2 | Passes all known tests, but theoretically possible correlations have a very small chance of being observed. |
3 | Any theoretically possible correlations have a very small chance of being observed. (default level) |
4 | Highest possible luxury level, all 24 bits of mantissa are chaotic. |
Table 1: RANLUX luxury levels
Only two subroutines from ranlux.f are required. The
code has been slightly updated, with WRITE
statements commented
out. The test program seeds the RANLUX generator using the current time, and
outputs random numbers to terminal. Save the program to file
test.f
:
C ******************************************************************
C
C TEST PROGRAM FOR RANLUX.
C
C ******************************************************************
PROGRAM TEST
EXTERNAL RANLUX, RLUXGO
INTEGER I, ISEED
REAL RVEC(120)
ISEED = TIME()
PRINT 100, ISEED
C
C SEED THE PRNG AND GENERATE 120 RANDOM NUMBERS OF
C LUXURY LEVEL 4.
C
CALL RLUXGO(4, ISEED, 0, 0)
CALL RANLUX(RVEC, SIZE(RVEC))
C
C PRINT RANDOM NUMBERS.
C
PRINT 200, (RVEC(I), I = 1, SIZE(RVEC))
100 FORMAT (' RANLUX',/,' SEED: ',I12)
200 FORMAT (6(X,F8.6))
END
To compile the test program and RANLUX with GNU Fortran, run:
$ gfortran -o test test.f ranlux.f
The program outputs 120 random numbers of luxury level 4:
$ ./test
RANLUX
SEED: 1687102328
0.433812 0.856685 0.008795 0.099017 0.015968 0.691084
0.154365 0.327787 0.485561 0.365306 0.847963 0.756334
0.844179 0.354677 0.604249 0.918622 0.281928 0.697786
0.541654 0.183323 0.027947 0.960144 0.441679 0.658389
0.991320 0.455806 0.645073 0.117603 0.400514 0.295812
0.315806 0.245797 0.516511 0.304323 0.580483 0.420281
0.554101 0.045181 0.044151 0.395561 0.913209 0.485687
0.848857 0.233543 0.575320 0.724913 0.945621 0.436735
0.258745 0.387378 0.757489 0.094826 0.514825 0.097988
0.333807 0.171438 0.329273 0.228922 0.851492 0.654191
0.293709 0.771061 0.392702 0.760998 0.659895 0.138509
0.793358 0.212885 0.597887 0.676509 0.542798 0.891888
0.625209 0.398726 0.291408 0.103916 0.623113 0.959293
0.614621 0.673251 0.648560 0.143696 0.814587 0.695696
0.982396 0.109548 0.510552 0.679046 0.560981 0.448637
0.225945 0.068281 0.945896 0.981980 0.919084 0.185577
0.977621 0.672705 0.736802 0.848577 0.055036 0.974460
0.277078 0.519698 0.158836 0.603521 0.820994 0.268041
0.164267 0.092804 0.617552 0.697459 0.193180 0.759857
0.560984 0.781850 0.156559 0.758775 0.345408 0.259962
acpr_v1_0.gz
)RANLUX.FOR
)