Statistics
| Branch: | Revision:

root / include / random.h @ 47c4b975

History | View | Annotate | Download (1.69 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  RANDOM.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//
7
//  Random number generator functions
8
//
9
//==========================================================================
10
11
/*--------------------------------------------------------------*
12
  Copyright (C) 1992-2008 Andras Varga
13
  Copyright (C) 2006-2008 OpenSim Ltd.
14

15
  This file is distributed WITHOUT ANY WARRANTY. See the file
16
  `license' for details on this and other legal matters.
17
*--------------------------------------------------------------*/
18
19
#ifndef __RANDOM_H
20
#define __RANDOM_H
21
22
#include "simkerneldefs.h"
23
#include "csimulation.h"
24
#include "cmodule.h"
25
#include "crng.h"
26
#include "cenvir.h"
27
28
NAMESPACE_BEGIN
29
30
31
// helper: return the "current" RNG.
32
inline cRNG *__contextModuleRNG(int k) {
33
    return simulation.getContextModule() ? simulation.getContextModule()->getRNG(k) : ev.getRNG(k);
34
}
35
36
/**
37
 * @ingroup RandomNumbers
38
 * @defgroup RandomNumbersGen Random number generation
39
 */
40
//@{
41
42
/**
43
 * Produces a random integer in the range [0,r) using generator 0.
44
 */
45
inline long intrand(long r)  {return __contextModuleRNG(0)->intRand(r);}
46
47
/**
48
 * Produces a random double in the range [0,1) using generator 0.
49
 */
50
inline double dblrand()  {return __contextModuleRNG(0)->doubleRand();}
51
52
/**
53
 * Produces a random integer in the range [0,r) using generator k.
54
 */
55
inline long genk_intrand(int k,long r)  {return __contextModuleRNG(k)->intRand(r);}
56
57
/**
58
 * Produces a random double in the range [0,1) using generator k.
59
 */
60
inline double genk_dblrand(int k)  {return __contextModuleRNG(k)->doubleRand();}
61
//@}
62
63
NAMESPACE_END
64
65
66
#endif
67