source: orange/orange/Orange/misc/random.py @ 9637:0e1d4c68f16b

Revision 9637:0e1d4c68f16b, 1.3 KB checked in by Jure Zbontar <jure.zbontar@…>, 2 years ago (diff)

Added documentation for RandomGenerator.

Line 
1"""
2
3.. index: Random number generator
4
5***********************
6Random number generator
7***********************
8
9:obj:`RandomGenerator` uses the
10`Mersenne twister <http://en.wikipedia.org/wiki/Mersenne_twister>`_ algorithm
11to generate random numbers.
12
13::
14
15    >>> import Orange
16    >>> rg = Orange.misc.random.RandomGenerator(42)
17    >>> rg(10)
18    4
19    >>> rg(10)
20    7
21    >>> rg.uses  # We called rg two times.
22    2
23    >>> rg.reset()
24    >>> rg(10)
25    4
26    >>> rg(10)
27    7
28    >>> rg.uses
29    2
30
31
32.. class:: RandomGenerator(initseed)
33
34    :param initseed: Seed used for initializing the random generator.
35    :type initseed: int
36
37    .. method:: __call__(n)
38
39        Return a random integer R such that 0 <= R < n.
40
41        :type n: int
42
43    .. method:: reset([initseed])
44
45        Reinitialize the random generator with `initseed`. If `initseed`
46        is not given use the existing value of attribute `initseed`.
47
48    .. attribute:: uses
49       
50        The number of times the generator was called after
51        initialization/reset.
52   
53    .. attribute:: initseed
54
55        Random seed.
56
57Two examples or random number generator uses found in the documentation
58are :obj:`Orange.evaluation.testing` and :obj:`Orange.data.Table`.
59
60"""
61
62from Orange.core import RandomGenerator
Note: See TracBrowser for help on using the repository browser.