Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: stevon8ter on December 07, 2012, 09:42:50 am

Title: [AXE] call a "random" subroutine
Post by: stevon8ter on December 07, 2012, 09:42:50 am
Hi guys

How would i be able to call a random subroutine?

I mean, if i have for example 5 subroutines...
EVENT1
EVENT2
EVENT3
EVENT4
EVENT5

how could i call one of those subroutines randomly?

for example when user does something, it should call a subroutine, but it has to be randomly chosen from that 5 (or maybe more...)
Title: Re: [AXE] call a "random" subroutine
Post by: squidgetx on December 07, 2012, 09:57:43 am
1.0.0 introduced a set of nice functions that can do this quite easily. The idea is to make a set of data containing the addresses of those routines, and then choose randomly from that set.

.Make set of data containing addresses of routines using the L list token
Data(LEVENT1r,LEVENT2r,LEVENT3r...LEVENTNr)->GDB1
.Choose randomly and execute that routine using the (LABELADDRESS)() syntax
({rand^n*2+GDB1}r)()
Title: Re: [AXE] call a "random" subroutine
Post by: stevon8ter on December 07, 2012, 10:35:58 am
oooh cool squidgetx :D

And doesn't the rand create something greater then 5 sometimes? :/
Title: Re: [AXE] call a "random" subroutine
Post by: Hayleia on December 07, 2012, 10:37:19 am
oooh cool squidgetx :D

And doesn't the rand create something greater then 5 sometimes? :/
Yes, this is the aim of the "^n" after the "rand". "rand^n" returns a random number between 0 and n-1
Title: Re: [AXE] call a "random" subroutine
Post by: stevon8ter on December 07, 2012, 10:40:38 am
oooh ok xD me so stupid :p
thx