3 ms·
Why the 205.5? Why wouldn't this work as 205 + RND(1)?
by SeanLuke 8y ago
Why the 205.5? Why wouldn't this work as 205 + RND(1)?
- scbrg 8y agoRND(1) returns a value between 0 and 1, but always lower than 1. Thus, the result of 205+RND(1) will always be 205 point something, which in turn will be truncated to 205. Thus, it will always result in the same character.
- SeanLuke 8y agoI see. RND returns a float.
- soneil 8y agoIt's more that the decimal is always rounded down. So you don't want a value between 205 and 205.9999999, as it'll always be rounded down to 205. you want a value between 205.5 and 206.49999999, so when rounded down it has a (practically) even chance of landing on either 205 or 206.
- Voltage 8y agoIn CBM BASIC RND(1) returned a floating point value between 0.0 (inclusive) and 1.0 (exclusive). 205 + RND(1) would always evaluate to 205 when truncated. 205.5 + RND(1) pseudo randomly selects between 205 and 206