0.6.2-dev0
FORCES
FORtran lib for Comp. Env. Sys.
Loading...
Searching...
No Matches
mo_xor4096::xor4096g Interface Reference

Gaussian XOR4096-based RNG. More...

Public Member Functions

subroutine xor4096gf_0d (seed, singlerealrn, save_state)
 
subroutine xor4096gf_1d (seed, singlerealrn, save_state)
 
subroutine xor4096gd_0d (seed, doublerealrn, save_state)
 
subroutine xor4096gd_1d (seed, doublerealrn, save_state)
 

Detailed Description

Gaussian XOR4096-based RNG.

Generates a gaussian distributed random number. First, a uniform distributed random number based on xor4096 algorithm is generated. Second, this number is transformed using the Polar method of Box-Mueller-transform to calculate the gaussian distributed numbers.


The original version of this source code (without multiple streams, optional arguments and gaussian distributed RN) is under GNU General Public Licence xorgens.c Copyright (C) 2004 R. P. Brent. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, June 1991, as published by the Free Software Foundation. For details see http://www.gnu.org/copyleft/gpl.html .

Author: Richard P. Brent (rando.nosp@m.m@rp.nosp@m.brent.nosp@m..co..nosp@m.uk)


The generator has to be called once with a non-zero seed value which initializes a new random number stream. The subsequent calls are with seed=0 which returns the following numbers within the beforehand initialized stream. Since the random numbers are based on the initial seed, the precison of the seed (sp/dp) determines the precision of the returned random number (sp/dp).
The returned values are gaussian distributed with mean 0 and variance 1.
The polar method of the Box-Mueller transform transforms two uniform distributed random numbers \(u_1\) and \(u_2\) into two gaussian distributed random numbers \(x_1\) and \(x_2\). First, two uniform numbers a1, a2 distributed between (-1,1) are calculated:

\[a_1 = 2u_1 - 1\]

\[a_2 = 2u_2 - 1\]

Second, \(q = a_1^2 + a_2^2\) is calculated. If ( \(q = 0\)) or ( \(q > 1\)) one has to generate a new \(x_1\) and \(x_2\), since a divison by q is needed afterwards and q needs to be distributed within the unit circle. Third,

\[p = \sqrt{-2 \frac{\ln{q}}{q}}\]

is calculated. The numbers \(z_1\) and \(z_2\) with

\[z_1 = a_1 p\]

\[z_2 = a_2 p\]

are then gaussian distributed with mean 0 and variance 1.

Example

See example for xor4096.

Literature

  1. Brent RP. Some long-period random number generators using shifts and xors, 2010
  2. Brent RP. From Mersenne Primes to Rndom Number Generators, 2006
  3. L''Ecuyer P & Simard R. ACM: TestU01: A C Library for Empirical Testing of Random Number Generators, 2007
  4. http://en.wikipedia.org/wiki/Marsaglia_polar_method
  5. http://de.wikipedia.org/wiki/Polar-Methode
Parameters
[in]integer(i4/i8) :: seed/seed(:)Value or 1D-array with non-zero seeds for initialization or zero for subsequent calls
[out]real(sp/dp) :: RN/RN(size(seed))Gaussian distributed random number with interval:
  • sp: RN ~ N(0.0_sp, 1.0_sp)
  • dp: RN ~ N(0.0_dp, 1.0_dp)
[in,out]integer(i4/i8), dimension(size(seed),n_save_state), optional :: save_stateArray carrying state of random number stream this should be used if several streams are used, i.e. each stream has its own save_state.
Note
  • The dimension of the optional argument can be set using the public module parameter n_save_state.
  • If random numbers are in single precision (sp), one needs seed and save_state in (i4).
  • If random numbers are in double precision (dp), one needs seed and save_state in (i8).
Author
Juliane Mai
Date
Nov 2011
Feb 2013
  • all optionals combined in save_state

Definition at line 287 of file mo_xor4096.f90.

Member Function/Subroutine Documentation

◆ xor4096gd_0d()

subroutine mo_xor4096::xor4096g::xor4096gd_0d ( integer(i8), intent(in)  seed,
real(dp), intent(out)  doublerealrn,
integer(i8), dimension(n_save_state), intent(inout), optional  save_state 
)

Definition at line 1766 of file mo_xor4096.f90.

◆ xor4096gd_1d()

subroutine mo_xor4096::xor4096g::xor4096gd_1d ( integer(i8), dimension(:), intent(in)  seed,
real(dp), dimension(size(seed)), intent(out)  doublerealrn,
integer(i8), dimension(size(seed), n_save_state), intent(inout), optional  save_state 
)

Definition at line 1929 of file mo_xor4096.f90.

◆ xor4096gf_0d()

subroutine mo_xor4096::xor4096g::xor4096gf_0d ( integer(i4), intent(in)  seed,
real(sp), intent(out)  singlerealrn,
integer(i4), dimension(n_save_state), intent(inout), optional  save_state 
)

Definition at line 1385 of file mo_xor4096.f90.

◆ xor4096gf_1d()

subroutine mo_xor4096::xor4096g::xor4096gf_1d ( integer(i4), dimension(:), intent(in)  seed,
real(sp), dimension(size(seed)), intent(out)  singlerealrn,
integer(i4), dimension(size(seed), n_save_state), intent(inout), optional  save_state 
)

Definition at line 1549 of file mo_xor4096.f90.


The documentation for this interface was generated from the following file: