Re: TIB: Random Number Generation Different From The One Before


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

Re: TIB: Random Number Generation Different From The One Before




I apologize to anyone sick of hearing me, but here's a better version
of the code in my last post.

This is a little bit faster than what I posted before, about 11
seconds for 24 values, including the time necessary to populate the
list, because I stored the list dimL to a var instead of actually
resizing the list and because I took out the stuff about adding the
values to a list to check them. This means that it will take .5 s on
average to get a random number, not terrible:

:seq(x,x,1,24)->LIST    ***Populate list
:24->LDIM                    ***This contains the "virtual" dimension
                                    ***of LIST. This way is faster
than
                                    ***actually resizing the list with
dimL
:
:While LDIM                ***While the list isn't empty
:
:iPart (LDIM*rand+1)->x    ***Random index among the list items
:
:Disp LIST(x)                ***Output the random number
:
:For(x,x,LDIM-1)        ***Move all the values after the selected one
                                  ***down one position, this comes out
to the
                                  ***same thing as removing that
                                  ***value from the list
:LIST(x+1)->LIST(x)
:End
:
:LDIM-1->LDIM
:End

I used something like this for a simple Blackjack games (with 4 lists
of 13 values though) and the time it took to get the random number
wasn't very noticeable.

Philipp Keller