Passing really big values to gsl_rng_uniform_int is not supported by the
library. Instead, add a function to generate any possible uintmax_t
value uniformly at random.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
#include <errno.h>
#include <assert.h>
#include <stdbool.h>
return gen_randomize_specs(rng, s);
}
+static uintmax_t gen_uintmax(struct gen_rng *rng)
+{
+ unsigned char tmp;
+ uintmax_t ret = 0;
+
+ for (size_t i = 0; i < sizeof ret; i++) {
+ tmp = gsl_rng_uniform_int(rng->rng, UCHAR_MAX+1);
+ ret <<= CHAR_BIT;
+ ret |= tmp;
+ }
+
+ return ret;
+}
+
/*
* Generate a random array declarator, selecting one of four possibilities
* uniformly at random.
d->u.array.length = 0;
break;
case 3:
- d->u.array.length = gsl_rng_uniform_int(rng->rng, -1);
+ d->u.array.length = gen_uintmax(rng);
break;
default:
assert(0);