It depends how random you want it to be.
If you want it to be completely random, you'll need to, every loop, create a variable with a random value and see if it equals, say 0. For example:
sync on
do
cls
rem Create random variable
random=rnd(49) : rem rnd(49) means 1 chance in 50 of the event happening every loop
rem Check to see if the event should happen
if random=0
print "Event!"
print "Press any key..."
suspend for key
endif
sync
loop
Then you'll need a way of choosing which event should happen. All you've got to do is create a random variable which chooses between the number of possible events and use the
select command to start the correct event. For example:
sync on
do
cls
rem Create random variable
random=rnd(49) : rem rnd(49) means 1 chance in 50 of the event happening every loop
rem Check to see if the event should happen
if random=0
rem Create a random event variable
event=rnd(4)+1 : rem rnd(4)+1 means it chooses between 5 possible events
rem 'Select' the event variable
select event
case 1 : rem Event number 1
print "Event 1!"
endcase
case 2 : rem Event number 2
print "Event 2!"
endcase
case 3 : rem Event number 3
print "Event 3!"
endcase
case 4 : rem Event number 4
print "Event 4!"
endcase
case 5 : rem Event number 5
print "Event 5!"
endcase
endselect
print "Press any key..."
suspend for key
endif
sync
loop
However, there is a problem with this way of doing it. Because it checks every loop if an event should happen, there is no set interval between checks. This means that if the FPS (frames per second) is high, the events would occur much more frequently than if the FPS is low, because it loops more often and so checks if the event should happen more often. This is not always a problem, but to get around this, you need to use a timer variable. It is easier to explain with an example:
sync on
rem Set the initial timer variable to now
timervar=timer()
do
cls
rem Find the difference in time (in milliseconds) between then last event check and now
timediff=timer()-timervar
rem If the difference is more than 250 milliseconds (1/4 of a second) then check if the event should happend
if timediff>=250
print "Checking if an event should happen..."
rem Create random variable
random=rnd(9) : rem rnd(9) means 1 chance in 10 of the event happening
rem Check to see if the event should happen
if random=0
print "Event!"
print "Press any key..."
suspend for key
endif
rem Reset the timer variable to now
timervar=timer()
endif
sync
loop
This checks every loop to see if the time between the last event check and now is more than 250 milliseconds. If it is, it checks to see if the event should happen.
This is all very well if you want the events to happen at purely random times. However if you want the chances of the events happening to increase (e.g. the chances of Joe saying he is hungry to increase as he gets more hungry), then you need to use a different system. Basically you just change the chances of the event happening by changing the number in the brackets of the
rnd() command based on a variable. If you want the chances to increase as a variable decreases (e.g. the chances of Joe saying he is tired increasing as the energy variable decreases) you just need to put that variable in the brackets of the
rnd() command (as long as the variable is positive). If you want the chances of an event happening to increase as a variable increases (e.g. the chances of Joe saying he is hungry increasing as the hunger variable increases), you'll put the maximum value of that variable minus the value of the variable in the brackets of the
rnd() command. (e.g. rnd(100-hunger)). For example:
randomize timer()
sync on
rem Inisialise the variables
energy=100
hunger=0
maxhunger=100
do
cls
rem Decrease energy over time but keep it more or equal to 0
energy=energy-1
if energy<0 then energy=0
rem Increase hunger over time (but keep it less of equal to maxhunger
hunger=hunger+1
if hunger>maxhunger then hunger=maxhunger
print "Energy: ";energy
print "Hunger: ";hunger
rem Check if Joe should say he is tired
if rnd(energy)=0
print "Joe is tired."
print "Press any key..."
suspend for key
endif
rem Check if Joe should say he is hungry
if rnd(maxhunger-hunger)=0
print "Joe is hungry."
print "Press any key..."
suspend for key
endif
sync
loop

"There is no charge for awesomeness" - The Kung Fu Panda