http://www.atariage....s...t&p=1503409
Quote
bally=(rand&63)+8
OK, it's not magic, but I don't understand this stuff, so it's magic to me. I played around with what batari posted and it's pretty cool. For most numbers, you get a random number between 0 and the number that you used. For example, (rand&15) gives you a random number between 0 and 15 and (rand&10) gives you a number between 0 and 10. But if you use 2, 4, 8, 16, 32, 64, or 128, you don't get a random number between 0 and one of those numbers. For example, if you use (rand&16), you only get one of two random numbers, 0 or 16, there is nothing in between. This is a good thing to know. I'm sure it will be useful.
Adding a number at the end changes the starting position from 0 to whatever number that you used, but you can also multiply by 2 in case you need to skip every other number. So (rand&15)*2 gives you 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30. And (rand&15)*2+1 gives you 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31. I'm sure that will also be useful one day for some type of game.
Because it cuts out the need for extra if/then statements, this stuff slightly reminds me of modular arithmetic that I read about in RUN magazine and RUN's The Best of Magic and used on my Commodore 64. Here's something from page 43 of RUN's The Best of Magic:
Quote
10 X=(X+1)-INT(X/12)*12
Here's a more general form of doing the same thing for different modulos:
20 DEF FNM(X) = (X+1)-INT(X/MAX)*MAX
The variable MAX should be the last number allowed before the counter rolls over to 1. Unlike much computer counting, modulo counting starts at 1, rather than 0.
~Dave Straub, Petaluma, CA
To avoid using unnecessary if/then statements, I also used stuff like this on my Commodore 64:
C=-((C=0)*11+(C=11)*12+(C=12)*15+(C=15))
C=-((C=1)*15+(C=15)*12+(C=12)*11+(C=11)*0)
X=(J=4)*8-(J=8)*8
Do you think batari Basic can or will ever be able to do modular arithmetic and the stuff I posted above?
Edited by Random Terrain, Sun Apr 20, 2008 12:01 PM.














