int add_dir(register FILEDESC *);
+static unsigned long my_random(unsigned long base)
+{
+ FILE * fp;
+ unsigned long long l = 0;
+ if (getenv("FORTUNE_MOD_USE_SRAND"))
+ {
+ goto fallback;
+ }
+ fp = fopen("/dev/urandom", "rb");
+ if (! fp)
+ {
+ goto fallback;
+ }
+ if (fread(&l, sizeof(l), 1, fp) != 1)
+ {
+ fclose(fp);
+ goto fallback;
+ }
+ fclose(fp);
+ return l % base;
+fallback:
+ return random() % base;
+}
+
static char *program_version(void)
{
static char buf[BUFSIZ];
if (Equal_probs)
{
- choice = random() % parent->num_children;
+ choice = my_random(parent->num_children);
DPRINTF(1, (stderr, " choice = %d (of %d)\n",
choice, parent->num_children));
for (fp = parent->child; choice--; fp = fp->next)
else
{
get_tbl(parent);
- choice = (int)(random() % (long)(parent->tbl.str_numstr));
+ choice = (int)(my_random(parent->tbl.str_numstr));
DPRINTF(1, (stderr, " choice = %d (of %ld)\n",
choice, parent->tbl.str_numstr));
for (fp = parent->child; choice >= (int)fp->tbl.str_numstr;
assert(fp->read_tbl);
if (fp->pos == POS_UNKNOWN)
{
- fp->pos = (int32_t)(random() % fp->tbl.str_numstr);
+ fp->pos = (int32_t)(my_random(fp->tbl.str_numstr));
}
if (++(fp->pos) >= (int32_t)fp->tbl.str_numstr)
fp->pos -= fp->tbl.str_numstr;
fp = File_list;
else
{
- choice = random() % 100;
+ choice = my_random(100);
DPRINTF(1, (stderr, "choice = %d\n", choice));
for (fp = File_list; fp->percent != NO_PROB; fp = fp->next)
if (choice < fp->percent)
if (fp->next != NULL)
{
sum_noprobs(fp);
- choice = (int)(random() % (long)Noprob_tbl.str_numstr);
+ choice = (int)(my_random(Noprob_tbl.str_numstr));
DPRINTF(1, (stderr, "choice = %d (of %ld) \n", choice,
Noprob_tbl.str_numstr));
while (choice >= (int)fp->tbl.str_numstr)