/* See {Random.h} */ #include /* Last edited on 2024-11-14 05:12:51 by stolfi */ #define Random_C_author \ "Created by J. Stolfi on 2007-02-01." #define _GNU_SOURCE #include #include #include struct Random_t { struct drand48_data state; }; Random_t *MakeRandomSource(long int seed) { Random_t *coins = (Random_t *)notnull(malloc(sizeof(Random_t)), "no mem"); srand48_r(seed, &(coins->state)); return coins; } double RandomDouble(Random_t *coins, double lo, double hi) { double x; drand48_r(&(coins->state), &x); return lo + (hi - lo)*x; }