diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-10-28 11:39:45 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-10-28 11:39:45 -0400 |
| commit | e27211417ab0538096e773bd9afa585651500839 (patch) | |
| tree | 8478534a312ec63ad03215b1e4b4b87fc61f7519 /rand.c | |
| parent | 36623f17ca2194fbb614a3cbce6b887734418f06 (diff) | |
| download | balls-e27211417ab0538096e773bd9afa585651500839.zip | |
variable radius
Diffstat (limited to 'rand.c')
| -rw-r--r-- | rand.c | 30 |
1 files changed, 14 insertions, 16 deletions
@@ -3,7 +3,20 @@ #include "balls.h" -static float randFloat(float lo, float hi); +float +randFloat(float lo, float hi) { + float r, diff; + static int isInitialized = 0; + + if (!isInitialized) { /* First call. */ + srand(time(0)); + isInitialized = 1; + } + + r = (float) rand() / RAND_MAX; + diff = hi - lo; + return lo + r*diff; +} float2 randPtInRect(Rectangle r) { @@ -19,18 +32,3 @@ randVec(float xmin, float xmax, float ymin, float ymax) { float2 v = {randFloat(xmin, xmax), randFloat(ymin, ymax)}; return v; } - -static float -randFloat(float lo, float hi) { - float r, diff; - static int isInitialized = 0; - - if (!isInitialized) { /* First call. */ - srand(time(0)); - isInitialized = 1; - } - - r = (float) rand() / RAND_MAX; - diff = hi - lo; - return lo + r*diff; -} |