5 ms·
He is not right either... 15 is 0xF. 16 is 0x10.
by gmrple 13y ago
He is not right either... 15 is 0xF. 16 is 0x10.
- acegopher 13y agoRight, the reason it won't ever emit F is because RND(1) will never return 1, it's implementation will return 0<=X<1, and INT() is a truncation, so INT(RND(1) + 15) will return an integer between 0 and 14. Adding one gives 1 to 15, and since F is in the 16th position of the string (Apple BASIC indexed from 1, not 0) it will never get selected.
- jamesbrownuhh 13y agoINT(RND(1)+15) will always return 15 and nothing else, since the expected output would be a rounded-down integer value of (a random number between 0 and 0.99999999etc999, plus 15). INT(RND(1) * 15), in contrast will produce a random whole number from 0 to 14. Hence the popular use of, for example, INT(RND(1) * 6)+1 in any given situation where a random number between 1 and 6 is required.
- acegopher 13y agoCorrect... my mistake, I put "+" when the original code was "*".
- fr0sty 13y agoHe is correct, that the value 16 given to MID$ as a 'start' will yield an "F" because the 'start' argument to the MID$ function is one-based. This is the string: A$ = "0123456789ABCDEF" And calling the function will give you: MID$ (A$,1,1) => "0" ... MID$ (A$,15,1) => "E" MID$ (A$,16,1) => "F" MID$ (
- Falling3 13y agoAh, thanks! I was scratching my head on that one...
- delinka 13y agoBut they're using MID to extract a character from the string. Seems to me that string indexes are 1-based in Apple BASIC as evidenced by the " ... + 1" and the fact that there are 0's on the page. So you select from characters 1 to 16 in the string. Edit: seems I was slower than all the other replies...