Visual Servoing Platform
version 3.0.1
Main Page
Related Pages
Modules
Namespaces
Classes
Examples
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
vpUniRand.cpp
1
/****************************************************************************
2
*
3
* This file is part of the ViSP software.
4
* Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5
*
6
* This software is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* ("GPL") version 2 as published by the Free Software Foundation.
9
* See the file LICENSE.txt at the root directory of this source
10
* distribution for additional information about the GNU GPL.
11
*
12
* For using ViSP with software that can not be combined with the GNU
13
* GPL, please contact Inria about acquiring a ViSP Professional
14
* Edition License.
15
*
16
* See http://visp.inria.fr for more information.
17
*
18
* This software was developed at:
19
* Inria Rennes - Bretagne Atlantique
20
* Campus Universitaire de Beaulieu
21
* 35042 Rennes Cedex
22
* France
23
*
24
* If you have questions regarding the use of this file, please contact
25
* Inria at visp@inria.fr
26
*
27
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29
*
30
* Description:
31
* Generation of random number with uniform and normal probability density.
32
*
33
* Authors:
34
* Eric Marchand
35
*
36
*****************************************************************************/
37
38
#include <math.h>
39
#include <visp3/core/vpUniRand.h>
40
46
inline
void
47
vpUniRand::draw0()
48
{
49
long
k=
x
/q;
//temp value for computing without overflow
50
x
= a*(
x
-k*q)-k*r;
51
if
(
x
< 0)
x
+= m;
//compute x without overflow
52
}
53
61
double
62
vpUniRand::draw1
()
63
{
64
const
long
ntab = 33;
//we work on a 32 elements array.
65
//the 33rd one is actually the first value of y.
66
const
long
modulo = ntab-2;
67
68
static
long
y = 0;
69
static
long
T[ntab];
70
71
long
j;
//index of T
72
73
//step 0
74
if
(!y) {
//first time
75
for
(j = 0; j < ntab; j++) {
76
draw0();
77
T[j]=
x
;
78
}
//compute table T
79
y=T[ntab-1];
80
}
81
82
//step 1
83
j = y & modulo;
//compute modulo ntab+1 (the first element is the 0th)
84
85
//step 3
86
y=T[j];
87
double
ans = (double)y/normalizer;
88
89
//step 4
90
//generate x(k+i) and set y=x(k+i)
91
draw0();
92
93
//refresh T[j];
94
T[j]=
x
;
95
96
return
ans;
97
}
vpUniRand::draw1
double draw1()
Definition:
vpUniRand.cpp:62
vpUniRand::x
long x
Definition:
vpUniRand.h:75
local
soft
ViSP
ViSP-web-script
visp
modules
core
src
math
random-generator
vpUniRand.cpp
Generated by
1.8.6