-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.c
40 lines (31 loc) · 1.17 KB
/
utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <math.h>
#include <stdlib.h>
#include "const.h"
#include "utils.h"
/*----------------------------------------------------------------------*/
/* This function returns a random real number between the specified */
/* inner and outer bounds. */
/*----------------------------------------------------------------------*/
long double random_number(long double inner, long double outer)
{
long double range;
range = outer - inner;
return((((long double)rand()) / (long double)(RAND_MAX)) * range + inner);
}
/*----------------------------------------------------------------------*/
/* This function returns a value within a certain variation of the */
/* exact value given it in 'value'. */
/*----------------------------------------------------------------------*/
long double about(long double value, long double variation)
{
return(value + (value * random_number(-variation,variation)));
}
long double random_eccentricity()
{
long double e;
e = 1.0 - pow(random_number(0.0, 1.0), ECCENTRICITY_COEFF);
if (e > .99) // Note that this coresponds to a random
e = .99; // number less than 10E-26
// It happens with GNU C for -S254 -W27
return(e);
}