The implementation of y = random(x) now looks roughly like:
temp_global = x;
if (temp_global > 0) {
y = (@random temp_global) + 1;
}
else {
@setrandom (-temp_global);
y = 0;
}
(This isn't legal I6 assembly but it gets the idea across.)
The minus sign in the @setrandom case means that random(-1) does @setrandom 1. I think this is slightly cleaner for testing.
If x is a compile-time constant, we can skip the branch and simply compile one of (@random CONST) + 1 or @setrandom CONST. As a result, this change does not affect the compiled output of random(CONST) for positive CONST.
The multi-argument random(C1, C2, C3...) case is not affected by this change either.
This change does affect the compiled output of Glulx games that use the standard library (I6 or I7). They will now be slightly larger: about 50 bytes for a minimal I6 game, about 200 for an I7 game. Glulx users are not likely to worry about this.
See https://github.com/DavidKinder/Inform6/issues/255 .
The implementation of
y = random(x)
now looks roughly like:(This isn't legal I6 assembly but it gets the idea across.)
The minus sign in the
@setrandom
case means thatrandom(-1)
does@setrandom 1
. I think this is slightly cleaner for testing.If
x
is a compile-time constant, we can skip the branch and simply compile one of(@random CONST) + 1
or@setrandom CONST
. As a result, this change does not affect the compiled output ofrandom(CONST)
for positive CONST.The multi-argument
random(C1, C2, C3...)
case is not affected by this change either.This change does affect the compiled output of Glulx games that use the standard library (I6 or I7). They will now be slightly larger: about 50 bytes for a minimal I6 game, about 200 for an I7 game. Glulx users are not likely to worry about this.