I guess RAND_MAX is a bit misguided here, but I can fix it later, shouldn't do any harm anyway