2013-09-13 17:49:28 +02:00
|
|
|
.. index:: Random number generator
|
|
|
|
|
2014-05-29 21:35:00 +02:00
|
|
|
.. module:: pytriqs.random_generator
|
2013-09-13 17:49:28 +02:00
|
|
|
|
|
|
|
.. _random_generator:
|
|
|
|
|
|
|
|
Random generator class
|
|
|
|
======================
|
|
|
|
|
2014-05-29 21:35:00 +02:00
|
|
|
TRIQS exposes to python the random number generators used in C++,
|
|
|
|
in the module ``RandomGenerator``.
|
|
|
|
The generators are the boost random generators.
|
2013-09-13 17:49:28 +02:00
|
|
|
|
|
|
|
Usage
|
|
|
|
-----
|
|
|
|
|
2014-05-29 21:35:00 +02:00
|
|
|
The generator is constructed from a name (the name of the boost generator) and a seed::
|
2013-09-13 17:49:28 +02:00
|
|
|
|
2014-05-29 21:35:00 +02:00
|
|
|
from pytriqs.random_generator import *
|
2013-09-13 17:49:28 +02:00
|
|
|
r = RandomGenerator("mt19937", 237849)
|
|
|
|
|
2014-05-29 21:35:00 +02:00
|
|
|
A list of available random generators is obtained with::
|
2013-09-13 17:49:28 +02:00
|
|
|
|
2014-05-29 21:35:00 +02:00
|
|
|
print random_generator_names_list()
|
2013-09-13 17:49:28 +02:00
|
|
|
|
2014-05-29 21:35:00 +02:00
|
|
|
Then you can either generate float number on the interval :math:`[0,1[`
|
|
|
|
simply by calling the generator, or integer numbers in the inverval :math:`[0,N-1]` by calling
|
|
|
|
it with `N` ::
|
2013-09-13 17:49:28 +02:00
|
|
|
|
2014-05-29 21:35:00 +02:00
|
|
|
print r()
|
|
|
|
print r(10)
|
2013-09-13 17:49:28 +02:00
|
|
|
|
|
|
|
Example
|
|
|
|
-------
|
|
|
|
|
|
|
|
Here's a simple example showing how to use the generator.
|
|
|
|
|
|
|
|
.. plot:: reference/python/random/random.py
|
|
|
|
:include-source:
|
|
|
|
:scale: 70
|
|
|
|
|
|
|
|
|
|
|
|
Complete reference
|
|
|
|
------------------
|
|
|
|
|
2014-05-29 21:35:00 +02:00
|
|
|
.. autoclass:: pytriqs.random_generator.RandomGenerator
|
2013-09-13 17:49:28 +02:00
|
|
|
:members:
|
|
|
|
|
2014-05-29 21:35:00 +02:00
|
|
|
.. autofunction:: pytriqs.random_generator.random_generator_names_list
|