Index: runtime/parrot/library/Math/Rand.pir =================================================================== --- runtime/parrot/library/Math/Rand.pir (revision 37081) +++ runtime/parrot/library/Math/Rand.pir (working copy) @@ -67,6 +67,12 @@ $I0 = $P0 $I0 *= 1103515245 $I0 += 12345 + ge $I0, 0, noadj + $I0 += 0x80000000 # not hit for 64bit int + goto done +noadj: + $I0 &= 0xffffffff # noop for 32bit int +done: set $P0, $I0 $I0 /= 65536 $I0 %= 32768 Index: t/library/rand.t =================================================================== --- t/library/rand.t (revision 37081) +++ t/library/rand.t (working copy) @@ -41,11 +41,11 @@ .end CODE 16838 -5759 +5758 10113 -17516 +17515 16838 -5759 +5758 OUTPUT pir_output_is( << 'CODE', << 'OUTPUT', 'RAND_MAX' );