3
0
mirror of https://github.com/triqs/dft_tools synced 2024-11-01 19:53:45 +01:00
dft_tools/doc/reference/python/random/random.rst
Michel Ferrero 2921cbcc06 Cythonize random generators
A trivial cythonized version of the c++ random_generator class.
Useful to get the names of the generators from the python.

  new file:   pytriqs/random/*
  new file:   doc/reference/python/random/*
2013-09-16 12:20:06 +02:00

49 lines
1.0 KiB
ReStructuredText

.. index:: Random number generator
.. module:: pytriqs.random
.. _random_generator:
Random generator class
======================
TRIQS has a simple random number generator class called ``RandomGenerator``. It is based on boost
just like the C++ random generator provided by TRIQS.
Usage
-----
The generator is constructed from a name and a seed::
from pytriqs.random import *
r = RandomGenerator("mt19937", 237849)
A list of possible random generator names is obtained with::
print available_generator_names()
Then you can either generate float number on the interval :math:`[0,1[` using
the ``rand()`` method or integer numbers in the inverval :math:`[0,N-1]` using
``int_rand(N)``::
print r.rand()
print r.int_rand(10)
Example
-------
Here's a simple example showing how to use the generator.
.. plot:: reference/python/random/random.py
:include-source:
:scale: 70
Complete reference
------------------
.. autoclass:: pytriqs.random.RandomGenerator
:members:
.. autofunction:: pytriqs.random.available_generator_names