I'm in need of a routine that returns a random integer between the minimum value passed in the 'a' register and the maximum value passed in the 'b' register. This routine needs to be in an app, so I would rather not use a library routine (of course I could always just use the routine itself in the app, but is there a simpler way?)
What do you have against the standard iRandom library? It returns a number between 0 and max, so all you need to do is set max=(b-a), and then add a to the result. In other words:

Your_random_val = a+iRandom(0,b-a)

Edit: And before you tell me I ignored your "no libraries" caveat, remember that the Ion source is freely available.
I know I CAN use it, I was just asking about alternatives. Although just using the routine's source may be easiest.
That would work. GlassOS uses a random number generator run by the interrupt. I would recommend just using the source and get coding Wink
ACagliano wrote:
I know I CAN use it, I was just asking about alternatives. Although just using the routine's source may be easiest.
You could implement yourself a nice simple LFSR-based random number generator, such as a Mersenne Twister. There is tons of example code online for that.
Ok. Will do!

One more thing: Where can I file a bug report for WabbitCode. It crashes all the time on OS X. Hangs, then crashes.
bump....!!

Also, slightly off topic:

1. Should bullet code and enemy AI position updates (in a game) occur once per cycle of the main loop, or via a custom interrupt routine? What is the recommendation for this?

2. If the answer to #1 is interrupts, is there a distinct way to invoke a custom interrupt within an APP? Or would this being an APP cause you to recommend "cycle" for #1 Wink ?
ACagliano wrote:
bump....!!

Also, slightly off topic:

1. Should bullet code and enemy AI position updates (in a game) occur once per cycle of the main loop, or via a custom interrupt routine? What is the recommendation for this?

2. If the answer to #1 is interrupts, is there a distinct way to invoke a custom interrupt within an APP? Or would this being an APP cause you to recommend "cycle" for #1 Wink ?

You can totally do interrupts in an APP just like you can in a program, and you can do them the same way: just copy the interrupt stub to the appropriate location, set the vector, and start IM 2. However, I would not do the actual updates of bullets and enemies in an interrupt routine, simply because it takes too many processor cycles to run all that logic. Instead, I would update a timer variable and have your enemies move a certain amount each tick.
ACagliano wrote:
Ok. Will do!

One more thing: Where can I file a bug report for WabbitCode. It crashes all the time on OS X. Hangs, then crashes.
You can post bug reports in the WabbitStudio thread here on Cemetech.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement