lib: random() is too slow

random() being a good multithread-safe RNG is too slow to be used in
stress tests, especially for a seemingly trivial task of randomising the
order of an array.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Chris Wilson 2014-12-18 09:08:13 +00:00
parent 6999b70a84
commit 71e9e9c564

View File

@ -190,6 +190,15 @@ void igt_exchange_int(void *array, unsigned i, unsigned j)
int_arr[j] = tmp; int_arr[j] = tmp;
} }
static uint32_t
hars_petruska_f54_1_random_unsafe(void)
{
static uint32_t state = 0x12345678;
#define rol(x,k) ((x << k) | (x >> (32-k)))
return state = (state ^ rol (state, 5) ^ rol (state, 24)) + 0x37798849;
#undef rol
}
/** /**
* igt_permute_array: * igt_permute_array:
* @array: pointer to array * @array: pointer to array
@ -209,7 +218,7 @@ void igt_permute_array(void *array, unsigned size,
for (i = size - 1; i > 1; i--) { for (i = size - 1; i > 1; i--) {
/* yes, not perfectly uniform, who cares */ /* yes, not perfectly uniform, who cares */
long l = random() % (i +1); long l = hars_petruska_f54_1_random_unsafe() % (i +1);
if (i != l) if (i != l)
exchange_func(array, i, l); exchange_func(array, i, l);
} }