## My SciELO

## Services on Demand

## Journal

## Article

## Indicators

- Cited by SciELO

## Related links

- Similars in SciELO

## Share

## Revista Cubana de Ciencias Informáticas

##
*On-line version* ISSN 2227-1899

### Rev cuba cienc informat vol.8 no.1 La Habana Jan.-Mar. 2014

**ARTÍCULO ORIGINAL**

**Improvement algorithm of random numbers generators used intensively on simulation of stochastic processes**

**Algoritmo de mejora de los generadores de números aleatorios usados intensivamente en la simulación de procesos estocásticos**

** Edisel Navas Conyedo ^{1*}, Carlos Torres Pupo^{1}, Giuseppe B. Suffritti^{2}, Jorge Gulín González^{3}**

1 Grupo de Matemática y Física Computacional. Universidad de las Ciencias Informáticas, Carretera a San Antonio de los Baños, km 2½, Torrens, Boyeros, La Habana, Cuba. CP.: 19370

2 Dipartimento di Chimica, Università de glistudi di Sassari, and Consorzio Ineruniversitario Nazionale per la Scienza e Tecnologiade i Materiali (INSTM), Unità di ricerca di Sassari, Via Vienna, 2, I-07100 Sassari, Italy

3 Dirección de Investigaciones. Universidad de las Ciencias Informáticas, Carretera a San Antonio de los Baños, km 2½, Torrens, Boyeros, La Habana, Cuba. CP.: 19370

*Autor para la correspondencia: enavas@uci.cu

**RESUMEN**

La elección de algoritmos eficaces y eficientes para la generación de números aleatorios es un problema clave en simulaciones de procesos estocásticos; siendo la difusión uno de ellos. El modelo del caminante aleatorio y la ecuación dinámica del Langevin son las formas más sencillas para el estudio computacional de la difusión. Ambos modelos, donde las partículas no interactúan y se mueven libremente, se utilizan para probar la calidad de los generadores de números aleatorios que se van a utilizar en simulaciones computacionales más complejas. En principio, la generación de números aleatorios a través de ordenadores es imposible porque los ordenadores funcionan a través de algoritmos deterministas, sin embargo, se pueden utilizar generadores deterministas cuyas secuencias de números que para las aplicaciones prácticas podrían considerarse aleatoria. En el presente trabajo se presenta una combinación de los generadores de números aleatorios reportados por Numerical Recipes y GNU Scientific Library con el que utiliza el sistema operativo Linux (basado en hardware). Los resultados obtenidos utilizando nuestra herramienta computacional permite mejorar las características aleatorias de le los generadores en estudio, con la mejora subsiguiente de la exactitud y la eficiencia de simulaciones computacionales de los procesos estocásticos.

**Palabras clave: ** Difusión, la ecuación dinámica de Langevin, generador de números aleatorios, paseo aleatorio, procesos estocásticos.

**ABSTRACT**

Choice of effective and efficient algorithms for generation of random numbers is a key problem in simulations of stochastic processes; diffusion among them. The random walk model and the Langevin's dynamical equation are the simplest ways to study computationally the diffusion. Both models, in the non-interacting free particles approximation, are used to test the quality of the random number generators which will be used in more complex computational simulations. In principle, generation of random numbers via computers is impossible because computers work through determinist algorithms; however, there are determinist generators which generate sequences of numbers that for practical applications could be considered random. In the present paper we present a improve algorithm random number generator obtained from a combination of those reported by Numerical Recipes, GNU Scientific Library, and that used by Linux operating system (based on hardware). The results obtained using our computational tool allows to improve the random characteristics of any pseudorandom generator, and the subsequent improving of the accuracy and efficiency of computational simulations of stochastic processes.

**Key words: ** Diffusion, random walk, langevin's dynamical equation, random number generators, stochastic processes.

**INTRODUCTION**

Random Number Generator (RNG) is a key point for the simulation of stochastic processes, particularly when the Monte Carlo method is used. Diffusion is among most common phenomenona in nature; moreover it is suitable to be computationally studied. The simplest way to describe the diffusion is by using the random walk model (RWM) and the Langevin's dynamical equation (LDE). Both models, in the non-interacting free particles approximation, are used to test the quality of the random number generators (Janke, 2002; Passerat-Palmbach, 2013). In the first model, RNG is used to simulate the molecular displacement by jumping; in the second one, to simulate the force on each particle, when the thermal noise is considered. The results obtained by RWM and LDE allow to test the quality of the RNGs which will be used in more complex computational simulations.

Generating random numbers by using computers is, in principle, unmanageable, because computers work with deterministic algorithms. However, there are deterministic algorithms that produce sequences of random numbers which for practical proposes can be considered random; these algorithms are named pseudorandom. For many applications some statistical and empirical test are consider for select a RNG with desirable characteristics, the quality of the generators is often estimated by the number of statistics or empirical test that are satisfactory resolved; however, it is possible the case in which a good selection of a RNG taken into account the behavior in many tests, do not produce good results in computational simulations (Sánchez-Pajares and Yuste, 2002)(David P. Rosin, 2013) (Yates and Klingbeil, 2013). Large simulation processes need good accuracy of results and low run time consumption as criteria of RNG selection.

In this paper, we study the behavior of the solutions in case of diffusion of free non interacting particles by using the RWM and LDE; to generate random numbers we use some of the most popular RNG, they are: the reported in Numerical Recipes text (NR) (Press, et al., 2007), GNU Scientific Library (Galassi, et al., 2011), and finally, that used by the operating system LINUX, (Love, 2010) based on hardware. Here, we propose a new algorithm to improve the random characteristic of any pseudorandom generator, and subsequently improving the accuracy and efficiency of computational simulations of stochastic processes.

**COMPUTATIONAL METHODOLOGY**

In the selection of a generator of pseudorandom numbers (PRNG) to be used in simulations it is desirable the existence of good random properties. The last should be undertaken as an independent sequence of random numbers whith the same probability of occurrence. Besides they have a long period and computational efficiency taking into account: time of calculation, used memory, and portability (David, 2013).

The computational algorithms for generating a pseudorandom numbers can be classified as: one-step (Park and Miller, 1988) (Kirkpatrick and Stoll, 1981), many recurrence steps (Deng, *et al*., 2008), shift registers, linear feedback shift registers and non-linear generators (González and Pino, 1999). Overall, all the PRNGs generate a sequence depending on starting value called seed and, consequently, whenever they are initialized with a same value the sequence is repeated.

To improve the characteristics of a random generator it uses several mechanisms as PRNGs combination of lower quality, one example is the method of dual randomness in which one PRNG generate a vector of values =(V1,V2, ,Vs) and other PRNG selects it while their values are updated obtaining a PRNG that has a longer period. A detailed explanation of all of these algorithms can be found in the appendix of the book of a reference (Fishman, 1996).

The operating system GNU/Linux was the first to implement a PRNG on system kernel level, this implementation uses the ambiental noise from various devices such as network card, video, mouse, keyboard, read and write instructions in memory and disks that are combined and transformed using secure hash functions yielding a sequence of random bits that can be accessed by /dev/random and /dev/urandom devices. These devices are differed because /dev/random block read operations until the system has enough entropy in its noise sources to ensure the randomness of the bits to read, this is very positive when we get results with a high degree of randomness regardless of the computing time; /dev/urandom is not blocked allowing a faster response time at the expense of obtaining random numbers with less random properties (Gutterman, et al., 2006) (Love, 2010). The implementation of this PRNG is very simple follow a algorithms represented on a function **GetUrand **to obtain a uniform generator on [0;1] interval, that depends of the number N of random bits that was read.

**Function GetUrand**

**Read N bits from /dev/urandom file and set on X var**

**Return double X/(2 ^{N}-1)**

**End Function GetUrand**

The use of the generator core operating system GNU/Linux on the other hand has better features when the time between calls to the generator is sufficient enough to cause cumulative noise from the devices, is therefore not appropriate to use this generator for simulations with intensive random number generator calls, being necessary to design a strategy to mix the use of this generator with some others algorithms. One of the major deficiencies that have the PRNG is its sequences are determined by the random seed, this may be a mechanism that can be used to improve the characteristics of the PRNG if after a set of calls, optimized in correspondence with the computational architecture, the seed is restart using other PRNG of operating system, in each case by optimizing the number of iterations for which there is sufficient accumulated environmental noise, this method breaks the sequence of decreasing PRNG long-term correlation between the values of the sequence and increasing the random statistical properties. The algorithms to use this mechanism of improvements that we propose can use any PRNG, represented as **Rand** function, and depend of the number M of iterations to do the reseed as show on function **GetBetRand. **For the M estimation the relation between the mean speed of call of **Rand **and **GetUrand** are used as , that guaranty no a great impacts on run time calls and enough accumulative entropy on /dev/urandom device**.**

** **

**Function GetBetRand Count I IF (I equal to M) then Read N bits from /dev/urandom file and set on Seed var Reseed Rand with Seed var I=0 else I=I+1 EndIF Return call of Rand End Function GetBetRand**

**Basic models for the simulation of stochastic processes.**

Diffusive processes are stochastic processes whose behavior can be simply simulated through the random walker model (RW) and Langevin dynamics equation (DL).

The RW model is a basic model for the description of Brownian motion developed by Einstein (Einstein, 1956), this is consider a system of independent particles each time a small interval * t *perform a jump in its value

*l*position, so each particle has a course based on the number of intervals considered as whose rms value is:

where

*R*and

_{m}=< || >*N*is the iterations number, if the displacements are uncorrelated and all particles initially are in the origin marks the central limit theorem and

*R*->0 and thus R

_{m}_{2m}->Nl

^{2}.

In practice, a computer simulation model RW is to build a system *S *which particles move with displacements

(1) |

where *rand*(-1*,*1)1*,*2*,*3 are calls to a uniform selected PRNG on [-1,1] interval. It is known that the RW model is sensitive to long periodicity and correlation between the displacements generated, which if you do not have enough randomness can lead to absurd results, so it can be used as a tool to test the qualities of a RNG (Proykova, 2000) (Sánchez-Pajares and Yuste, 2002) (Janke, 2002).

The DL model is a simplified approach to describe the dynamics of a molecular system, this takes into account the interaction of each molecule with the environment in which broadcasts which is treated as a viscous medium and includes a term corresponding to the thermal agitation in the case of particles that do not interact with each other, it has the form:

(2) |

where *M *are the particles mass, * y *is the viscosity coefficient,

*T*is the temperature and

(3) |

is the noise function (Schlick, 2002). When rms is calculating this gives:

(4) |

for t=my^{-1} has linear behavior *R _{2m}(t)=.*

**RESULTADOS Y DISCUSIÓN**

To test the influence of PRNG on diffusion simulation of noninteracting free particles we have selected a set of 20 PRNGs where 7 correspond to the distribution of NR in its third version, 10 to a package of GSL in the version 1.15, 1 using the Linux kernel generator whose implementation for C that was shown before in section:2 and 2 whose corresponding with a mixture implementation using a one RNG of each distributions with seeds changing every 1024 calls by Linux kernel PRNG those are shown in table 1.

Importantly, the expressions (1) and (3) that are used to generate shifts in the RW model and noise in DL are highly influenced by the quality of the generator used, because the generation of random numbers corresponding to three consecutive calls are needed and implies that the sets of possible values generated can be limited by the correlations, the ability to generate 3 calls at least 2 components of equal value is almost null then all possible directions as ,, may not be generated.

For the simulation model RW we used a step 1 = 1, thus the theoretical value of the mean square displacement is R_{2m} = MN with M = 1. In the case of the simulation model DL we used the following parameters: m = 1, k_{B}T = 10^{-2}, γ = 10^{-3} where we use dimensionless t′ = t and ′ = thus obtaining for t′≫ 1 that R′2m = M(t′- 1) with M = 1, Euler method on (2) was used with Δt′ = 4 10-4 steep (Lambert, 1991).

The simulation was developed on a Intel(R) Xeon(R) CPU X5570 2.93 GHz 16 Cores 24 GB RAM PC with CENTOS LINUX 5.8 for the X86_64 architecture with kernel 2.6.18-348.3.1.el5, *S *= 6000 particles and 100000 iterations for each PRNG with 100 independents runs. By reduction we refer each PRNG as RNG on result analysis.

In Figure 1 we see the computational speed of each PRNG in correspondence with its algorithmic complexity, the slower PRNG corresponds to the Linux kernel PRNG because of multiple consecutive calls to the /dev/urandom virtual device are made. PRNGs with ID 19 and 20 which are a mixture using the random seeding procedure using the Linux kernel PRNG do not have a noticeable difference with the unmodified original PRNGs 14 and 2.

Analyzing the graphs presented in Figure 2 a) and b) we note two important aspects, firstly that compliance through the central limit S_{m} = _{it=1}^{100000}R_{m}/100000 depends not only on the implementation of the PRNG, also the model used as RW or DL, in this case DL being more consistent with the expected results, even though some PRNG shows similar behavior in comparison with the rest, however for the generators 19 and 20 shows a better performance in all cases.

Figure 3 show the average deviation of the theoretical value using two ways to adjust the linear behavior of the equation 4 on each PRNG, S_{m}= MIt+ b and S_{m} = M * It, in this case shows that the results for the RW model are more closely to theory expected results, however the PRNGs 19 and 20 have a notable improvement over the corresponding PRNG without seeding Figure 3 show the average deviation of the theoretical value using two ways to adjust the linear behavior of the equation 4 on each PRNG, S_{m} = MIt + b and S_{m} = M * It, in this case shows that the results for the RW model are more closely to theory expected results, however the PRNGs 19 and 20 have a notable improvement over the corresponding PRNG without seeding.

More details of other statistical tests for PRNGs can be consulted on the url:http://random.mat.sbg.ac.at/tests/ and (Maurer, 1992) (Rukhin, et al., 2001) (Passerat-Palmbach, 2013).

**CONCLUSIONES**

In general we observe that the influence of the PRNG in diffusion simulation for the proposed system is different, not only depending of used model, the information to be obtained also affects. In the study of central limit average behavior the DL model was better and the study of the standard deviation of the theoretical value was more appropriate RW model for the proposed system.

In all the cases we observe that the PRNG give better results when using PRNG seeding with the Linux kernel PRNG, this result is confirmed for all proposed PRNGs when the number of calls to reset is optimized such that time to gather enough operating system noise with the expression proposed, without affecting significantly the response speed of the PRNG, a factor which is principal for the development of long runs. We only show illustratively only two of the most widely PRNGs used. One per software distribution.

**REFERENCIAS BIBLIOGRÁFICAS**

DENG, L.-Y. RUI GUO, DENNIS K. J. LIN, and FENGSHAN BAI. Improving Random Number Generators in the Monte Carlo simulations via twisting and combining. Computer Physics Communications, (178):401-408, 2008.

DENHOLM LAMBERT, JOHN. Numerical Methods for Ordinary Differential Systems. John Wiley and Sons, Chichester, 1991, ISBN 0-471-92990-5.

EINSTEIN, A. Investigations on the theory of the brownian movement. Dover, 1956.

GONZÁLEZ, J. A. and PINO, R. A random number generator based on unpredictable chaotic functions. Computer Physics Communications, (120):109-114, 1999.

GALASSI, M.; JAMES THEILER, J. D.; GOUGH, B. et al. Gnu Scientific Library: Reference Manual. Network Theory Ltd., July 2011. ISBN 0954161734.URL [http://www.amazon.com/exec/obidos/redirect?tag=citeulike07-20&path=ASIN/0954161734].

GEORGE S. FISHMAN. Monte Carlo Concepts, Algorithms and Applications. Springer-Verlag, New York Berlin Heidelberg, 1996, ISBN 0-387-94527-X.

GUTTERMAN, Z.; PINKAS, B. and REINMAN, T. Analysis of the Linux Random Number Generator, March 2006. URL http://www.pinkas.net/PAPERS/gpr06.pdf.

JAMES, F. RANLUX: A Fortran implementation of the high-quality pseudo-random number generator of Lüscher. Computer Physics Communications, 79:111-114, 1994.

JANKE, W. Pseudo random numbers: Generation and quality checks. In Quantum Simulations of Complex Many-Body Systems: From Theory to Algorithms, Lecture Notes, volume 10, p. 447-458. NIC Series, John von Neumann Institute for Computing, Juelich, Germany, 2002. ISBN 3-00-009057-6. Disponible en: [http://www.fz-juelich.de/nic-series/volume10].

KIRKPATRICK, S. and STOLL, E. A very fast shift-register sequence random number generator. Journal of Computational Physics, 40:517-526, 1981.

L'ECUYER, P. Combined Multiple Recursive Random Number Generators. Operations Research, 44(5):816-822, 1996a.

L'ECUYER, P. Maximally Equidistributed Combined Tausworthe Generators. Mathematics of Computation, 65(213): 203-213, 1996b.

L'ECUYER, P. Tables of Maximally Equidistributed Combined LFSR Generators. Mathematics of Computation, 68 (225):261-269, 1999.

L'ECUYER, P.; BLOUIN, F. and COUTRE, R. A search for good multiple recursive random number generators. A search for good multiple recursive random number generators, 3:87-98, 1993.

LOVE, R. Linux Kernel Development. Novell Press/Pearson Education, 3rd edition, 2010. ISBN 0-672-32946-8.

LÜSCHER, M. A portable high-quality random number generator for lattice field theory calculations. Computer Physics Communications, 79:100-110, 1994.

MATSUMOTO, M. and NISHIMURA, T. Mersenne Twister: A 623-dimensionally equidistributed uniform pseudorandom number generator. ACM Transactions on Modeling and Computer Simulation, 8(1):3-30, January 1998.

MAURER, U. A Universal Statistical Test for Random Bit Generators. Journal of cryptology, 5:89-105, 1992.

PARK, R. AND M.. Number Generators: Good ones are hard to find. Communications of the ACM, 31(10): 1192-1201, October 1988.

PASSERAT-PALMBACH, J. Contributions to parallel stochastic simulation: Application of good software engineering practices to the distribution of pseudorandom streams in hybrid Monte-Carlo simulations. PhD thesis, School of Engineering Sciences of the Blaise Pascal University - Clermont II, LIMOS laboratory - UMR CNRS 6158, October 2013.

PRESS, W. H.; TEUKOLSKY, S. A.; VETTERLING, W. T. and B. P. FLANNERY. Numerical recipes in C++. The art of scientific computing. Cambridge: University Press, |c2007, Third Edition., 2007. ISBN 0521880688.

PROYKOVA, A. How to improve a random number generator. Computer Physics Communications, (124):125-131, 2000.

ROSIN, D. P.; RONTANI, D.; and GAUTHIER, D. J. Ultrafast physical generation of random numbers using hybrid boolean networks. Physical Review E, 87(040902), May 2013. doi:10.1103/PhysRevE.87.040902.

RUKHIN, A.; SOTO, J.; NECHVATAL, J.; et al. A statistical test suite for random and pseudorandom number generators for cryptographic applications, 2001.

SÁNCHEZ-PAJARES, H. and SANTOS BRAVO, Y. Una función random poco aleatoria. Revista española de física, 16 (2):60-62, 2002. ISSN 0213-862X.

TAMAR SCHLICK. Molecular Modeling and Simulation. Springer.pp, pages 435-438, 2002. ISSN 0-387-95404-X.

YATES, CH. A. and KLINGBEIL, G. Recycling random numbers in the stochastic simulation algorithm, January 2013. Disponible en: [http://people.maths.ox.ac.uk/yatesc/yates2013rrn.pdf].

ZIFF, R. M. Four-tap shift-register-sequence random-number generators. Computers in Physics, 12(4):385-392, July 1998.

Recibido: 27/09/2013

Aceptado: 15/11/2013