On illumos rand() has a RAND_MAX of 32k only. That's not enough to
generate 64bit values easily. So use mrand48() which genrerates
the full range of 32bit int values.
main(int argc, char *argv[])
{
assert(sizeof(long long) == 8);
- assert(RAND_MAX == INT32_MAX);
+ srand48(42L);
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-v") == 0)
uint64_t
get_random_value(IRType type)
{
- uint64_t val = rand();
+ uint64_t val = mrand48();
switch (type) {
case Ity_I1: return val & 0x1;
case Ity_I16: return val & UINT16_MAX;
case Ity_I32: return val & UINT32_MAX;
case Ity_I64:
- /* Note, that RAND_MAX == INT32_MAX. Therefore, simply concatenating
- two rand() values would never produce a value with MSB == 1 */
- val <<= (32 + 1);
- val |= rand() << 1;
- val |= rand() & 0x1;
+ val <<= 32;
+ val |= mrand48();
return val;
default: