|Re: RPL version|
Message #5 Posted by James M. Prange (Michigan) on 28 Aug 2007, 9:25 p.m.,
in response to message #4 by Vincze
It would be better to return character strings than global names, so I'd use "HEADS" and "TAILS" instead of 'HEADS' and 'TAILS'.
Assuming that the AUR manual is correct, RAND returns a value in the range 0<=x<1, so for true 50/50 probabilities, use something like:
\<< IF RAND .5 \>= THEN "HEADS" ELSE "TAILS" END \>>
\<< IF RAND .5 < THEN "TAILS" ELSE "HEADS" END \>>
In the above, "%%HP: T(3)A(R)F(.);" is an "ASCII transfer header" that would allow you to copy and paste the source code to a file for transferring to a calculator. It tells the calculator, first off, that it is an ASCII transfer, then which translation mode (0 through 3) to use, then which angular mode (DEG, RAD, or GRAD) to use, and which of period or comma is the "fraction mark". For small programs such as these, one would likely just key in the program, but the transfer header tells just how to key it in, although the angular mode doesn't matter for these particular cases.
"\<<" and "\>>" represent the UserRPL program delimiters, and "\>=" represents the "greater than or equal to" symbol.
In RPL source code, a "line" is pretty much meaningless, except that a LineFeed code always end any comment. You could put everything on a single line, use one line for each "word", indent some lines, or whatever you choose. If a source code delimiter doesn't already do so, then "separators", such as spaces, ASCII control codes, semicolon, or whichever of period or comma isn't the fraction mark, tell the compiler where one "word" ends and the next begins. Such source code "formatting" is up to the programmer, and each tends to use his own particular formatting "style"; for example, with a longer program, I'd use something like:
Getting back to RAND, it would be possible to cheat with your program by setting the seed with the RDZ command. With any given seed, the numbers returned by a series of RAND commands is repeatable, although rather difficult to "predict" without actually trying it, thus you could "preview" the sequence of "HEADS" and "TAILS" returned after "initializing" the seed with the RDZ command.