SX/B Random for jack-in-the-box
Hi All,
I'm building a Halloween prop that will be a large jack-in-the-box. The user will turn a crank on the side of the box that will send pulses to the SX which will trigger the play back, individually, of the 30 notes in the jack-in-the-box song from a ChipCorder. For scare value, instead of popping the "jack" up at the usual place in the song, I'd like to do it randomly.
What I'm thinking I'd like to do at the start of each sequence is generate a "random" integer between 5-30 (starting at 5 notes into the song so they think it's a normal jack-in-the-box), the SX would then count the pulses from the crank and when it got to this "random" number, trigger the "jack" to pop-up.
What I don't know how to do is to generate this integer between 5 and 30. I've looked at the RANDOM command in SX/B and somewhat understand it, I just don't know how I'd get the result to be an integer between 5 and 30. Any suggestions? This will be my first real SX project so I'm at the beginner level in using SX/B.
If anyone has a better way to do this, I'm open for ideas.
Thanks.
Terry
I'm building a Halloween prop that will be a large jack-in-the-box. The user will turn a crank on the side of the box that will send pulses to the SX which will trigger the play back, individually, of the 30 notes in the jack-in-the-box song from a ChipCorder. For scare value, instead of popping the "jack" up at the usual place in the song, I'd like to do it randomly.
What I'm thinking I'd like to do at the start of each sequence is generate a "random" integer between 5-30 (starting at 5 notes into the song so they think it's a normal jack-in-the-box), the SX would then count the pulses from the crank and when it got to this "random" number, trigger the "jack" to pop-up.
What I don't know how to do is to generate this integer between 5 and 30. I've looked at the RANDOM command in SX/B and somewhat understand it, I just don't know how I'd get the result to be an integer between 5 and 30. Any suggestions? This will be my first real SX project so I'm at the beginner level in using SX/B.
If anyone has a better way to do this, I'm open for ideas.
Thanks.
Terry
Comments
Remember that SX/B only allows one operator per line, so it takes two lines to do what you might do in one with PBASIC. The first line takes the modulus of your random value, returning a result of 0 to 25 (the span of your range). The next line bumps the minimum and maximum points to re-align to your desired output.
Can you expand a little on how you arrived with the value of 26. I assume that's the range from 0 to 25 but I don't quite understand how that works with the Modulus. (I haven't used Modulus in the past and I'm just barely understanding the concept.)
Also, rVal will be the random number between 0 and 255 generated by the RANDOM command given rVal is a byte. Is this correct?
Thanks,
Terry
Think of modulus as remainder. So you take the value and divide by 26, returning NOT the result of the division, but the remainder of the division.
Sounds like a cool project, I'd love to see some video of it after you get working.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
“The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
Post Edited (Bean (Hitt Consulting)) : 5/29/2007 11:35:16 AM GMT
Terry