Re: A89: Random number help, tables


[Prev][Next][Index][Thread]

Re: A89: Random number help, tables




ZeromusMog@aol.com wrote:
> In a message dated 4/10/99 1:41:28 PM Pacific Daylight Time,
> bentensai@yahoo.com writes:
> > You can userlib::random
> >  Here is an example.
> >
> >  you can write your question before this and this will
> >  send you randomly to an answer.
> >
> >   move.w #14,d0 ;uperlimit of random number
> >   jsr    userlib::random :put's a random number 0<x<14
> >  in d0.
> >   cmp.w  #0,d0  ; 0 is lowest number that can be gotten
> >   beq answer1     ; branches to answer one.
> >   cmp.w  #1,d0  ; check to see if one
> >   beq answer2   ; goes to answer two.
> >  And so on until it is 14.  I hope this helps.
> 
> Wouldn't some form of lookup table be more efficient?
> ::Runs away before he gets caught talking about things above his head::

I agree. That would be more efficient, specially with a lot of question-answer
sets, and cleaner code.
have all questions saved after each other, with the answers right after each q.
Then have a little table where you store the addresses of all the questions.
if you want question 5, pick out the fifth entry in the table, read the q until
you hit 0, then read in the answers. If you want different amount of answers to
each question, put in a little byte here telling how many answers to read.

If you build it up like this, it is very easy to add new questions, just put
them in, expand the table by one entry and increase the range of the
randomfunction.

//olle


References: