blob: 7a327ee94aa210a3b676f2fa72136faabf28a17d (
plain) (
blame)
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
|
#include "balls.h"
double
randDouble(double lo, double hi) {
double r, diff;
static int isInitialized = 0;
if (!isInitialized) { /* first call */
srand(time(0));
isInitialized = 1;
}
r = (double) rand() / (double) RAND_MAX;
diff = hi - lo;
return lo + r*diff;
}
Color
randColor(void) {
Color color;
color.r = randDouble(0, 1);
color.g = randDouble(0, 1);
color.b = randDouble(0, 1);
return color;
}
Point
randPtInRect(Rectangle r) {
return Pt(randDouble(r.min.x, r.max.x), randDouble(r.min.y, r.max.y));
}
|