Dr. Rudolf R.H. Dittrich — RD-AVENUE® : Research and Development Office for
Applied Physics and Engineering / System Software Development
Artificial Intelligence Applications / Numerical Methods / Embedded Systems + IoT / Software Documentation
Complex Systems
English Portal
» Complex Systems

German Portal
Beginning October 3, 2012 and largely depending on the rare breaks available while working on customer projects, this site is occassionally being edited and enlarged — We would enjoy welcoming you again on this page:

# Complex Systems

(First published Sept. 17, 2012. Last updated and extended Sept. 23, 2013)

## 1. Introduction

Beginning mid-October 2012, this page will be devoted to publish material on some selected aspects of complex systems like, for example, Monte Carlo simulations, elementary aspects of stochastics, fractal systems, Computational Physics / Numerics etc.
Interested readers are invited to visit this site again.

## 2. Elementary Questions and Answers

Some elementary questions and their answers can be found here:

## 3. First Remarks on Random Number Algorithms, Monte Carlo Simulations, etc.

In the few algorithms considered during the next months, we will need `N` independent random numbers where `N` may be a large number. One particularly simple way of generating `N` independent sequences of random numbers may consist in using `N` instances of a good enough one-dimensional random number generator each initialized with a different seed. One especially good example of a random generator with an exceptionally large period of 219937-1 is nowadays given by Makoto Matsumoto's and Takuji Nishimura's Mersenne Twister algorithm. At the time of this writing, the Mersenne Twister sources were available free of charge on M.Matsumoto's excellent homepage:

» www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html  Link to Mersenne Twister homepage

For those not using a recent C++11 compiler with its built-in implementation of the Mersenne Twister algorithms, we are recommending to use the code found on the above web site and use this to generate an `N`-dimensional sequence of random numbers. For brevity's sake, the Mersenne Twister sources are not repeated here. Instead, we are hinting on how the author of this page has been using `N` instances of another one-dimensional random generator in a simple C++ class. By way of example, we assume that we intend to use the C++ programming language for generating `N` independent series of uniform deviates of type `double` on the real interval `[0,1)` using a C++ class, henceforth called `CStochRan1`, which is making use of a one-dimensional random generator member function, called `ran1(long *lseed)`, where `*lseed` be a pointer to the random seed (note that the class definition would be more complicated in a real example; the following code snippets are just meant to show one of several possible ways for coding `N` independent random generators; solving real problems means that the code needs to be adjusted and extended according to the problem's needs):

``` class CStochRan1 { public: CStochRan1(void); ~CStochRan1(void); double ran1(long *lseed); private: // add private code here }; ```
An `N`-dimensional generalization may then be coded using a class definition similar to the following example:

```class CStochRanN { public: CStochRanN(unsigned int N, long *lseeds); ~CStochRanN(void); void ranN(long *lseed, double *r); void ranN(double *r); inline unsigned int GetDim(void); long Getlseeds(unsigned int idx); private: CStochRan1 **lstr; long *lseedArray; unsigned int Ndim; }; ``` where `CStochRan1` is the beforementioned class describing a one-dimensional random generator; `lseedArray` a long integer pointer to random seeds used by the one-dimensional algorithm; and `Ndim` the current number of dimensions which may be large.
The constructor `CStochRanN(unsigned int N, long *lseeds)` takes two arguments which are, respectively, the number, `N`, of independent random numbers, and a long pointer to an array containing `N` seeds. We are using `malloc(.,.)` to allocate the memory needed on the heap, create `N` instances of class `CStochRan1`, and initialize the array containing the random seeds:

```CStochRanN::CStochRanN(unsigned int N, long *lseeds) { Ndim = N; lseedArray = (long *)malloc((Ndim+1)*sizeof(long)); lstr = (CStochRan1 **)malloc((Ndim+1)*sizeof(CStochRan1 *)); for(unsigned int idx = 0; idx < (Ndim+1);idx++) lstr[idx] = NULL; for(unsigned int idx = 0; idx < Ndim;idx++) { lstr[idx] = new CStochRan1(); lseedArray[idx] = lseeds[idx]; } } ```
The destructor, `~CStochRanN(void)`, takes care of deleting the `CStochRan1` instances and freeing the memory previously allocated:

```CStochRanN::~CStochRanN(void) { for(unsigned int idx = 0; idx < Ndim; idx++) { if (lstr[idx] != NULL) delete lstr[idx]; } free(lstr); free(lseedArray); } ```
We are using two overloaded versions of the random number generator program. The first prototype allows for modifying the random seeds while being invocated. The resulting `N` random numbers, each the result of invoking a `ran1(.)` instance, are being accessed by pointer `*r`:

```void CStochRanN::ranN(long *lseed, double *r) { for(unsigned int idx = 0; idx < Ndim; idx++) { lseedArray[idx] = lseed[idx]; r[idx] = lstr[idx]->ran1(&lseedArray[idx]); lseed[idx] = lseedArray[idx]; } } ```
The second version may be used without modifying the random seeds on the fly:

```void CStochRanN::ranN(double *r) { for(unsigned int idx = 0; idx < Ndim; idx++) { r[idx] = lstr[idx]->ran1(&lseedArray[idx]); } } ```
The other methods, used for retrieving the number of independent random numbers and the value of the seeds, are just given for reference:

```inline unsigned int CStochRanN::GetDim(void) { return Ndim; } long CStochRanN::Getlseeds(unsigned int idx) { if (idx < Ndim) return lseedArray[idx];else return 0; } ```
Having available `N` independent random generators has given us a simple start for using this and similar code within our future example programs.

To be continued...

You may find additional information on complex systems by visiting the pages of the Complex Systems Society. At the time of this writing, their web site was accessible by following this link:

» Link to the Complex Systems Society

Please note again that this RD-AVENUE® site is not in any way related to this or other societies but is instead reflecting the personal view of its author only.