ARB
Main Page
Namespaces
Classes
Files
File List
File Members
TREEGEN
frand.c
Go to the documentation of this file.
1
#include "
frand.h
"
2
#include <math.h>
3
#include <stdlib.h>
4
5
static
double
randval
() {
6
// Liefert einen Zufallswert zwischen -0.5 und +0.5
7
double
val = rand();
8
9
val /= RAND_MAX;
10
val -= 0.5;
11
12
assert
(val>=-0.5);
13
assert
(val <= 0.5);
14
15
return
val;
16
}
17
static
double
lowfreqrandval
(
double
*val,
int
teiler) {
18
// Liefert einen niederfrequenten Zufallswert zwischen -0.5 und +0.5
19
double
add
=
randval
()/teiler;
20
21
*val +=
add
;
22
if
(*val<-0.5 || *val>0.5) *val -= 2*
add
;
23
24
return
*val;
25
}
26
Frand
initFrand
(
double
medium,
double
low,
double
high) {
27
Frand
f = (
Frand
)malloc(
sizeof
(*f));
28
29
if
(!f)
outOfMemory
();
30
31
f->
medium
= medium;
32
f->
alpha
= high*2;
33
f->
beta
= low*2;
34
f->
val
=
randval
();
35
f->
teiler
= 1;
36
37
return
f;
38
}
39
double
getFrand
(
Frand
f) {
40
return
f->
medium
+
41
f->
alpha
*
randval
() +
42
f->
beta
*
lowfreqrandval
(&(f->
val
), f->
teiler
);
43
}
44
void
freeFrand
(
Frand
f) {
45
free(f);
46
}
47
double
randProb
() {
48
// Liefert einen Zufallswert zwischen 0.0 und 1.0
49
double
val = rand();
50
51
val /= RAND_MAX;
52
53
assert
(val>=0.0);
54
assert
(val<=1.0);
55
56
return
val;
57
}
58
S_Frand
Definition:
frand.h:8
frand.h
S_Frand::val
double val
Definition:
frand.h:9
randval
static double randval()
Definition:
frand.c:5
add
void add(int v)
Definition:
ClustalV.cxx:461
S_Frand::beta
double beta
Definition:
frand.h:9
randProb
double randProb()
Definition:
frand.c:47
S_Frand::alpha
double alpha
Definition:
frand.h:9
freeFrand
void freeFrand(Frand f)
Definition:
frand.c:44
initFrand
Frand initFrand(double medium, double low, double high)
Definition:
frand.c:26
S_Frand::medium
double medium
Definition:
frand.h:9
lowfreqrandval
static double lowfreqrandval(double *val, int teiler)
Definition:
frand.c:17
getFrand
double getFrand(Frand f)
Definition:
frand.c:39
Frand
struct S_Frand * Frand
assert
#define assert(bed)
Definition:
arb_dnarates.cxx:36
outOfMemory
#define outOfMemory()
Definition:
defines.h:14
S_Frand::teiler
int teiler
Definition:
frand.h:13
Generated by
1.8.8