Advanced Random Function

I am currently loading images randomly for a slideshow and I would like to push it to the next level.

  • First, something that is probably more common (but I can’t find info) is to make sure the same image is not loaded twice consecutively.

  • Second, there are 3 categories in the slideshow, and I would like to see a picture from a different category every time. Currently, the category is defined in the XML as shown below.


<?xml version="1.0"?>
<menu>
<item  category="category 1" pic="1.jpg"/>
<item  category="category 1" pic="2.jpg"/>
<item  category="category 2" pic="3.jpg"/>
<item  category="category 2" pic="4.jpg"/>
<item  category="category 3" pic="5.jpg"/>
<item  category="category 3" pic="6.jpg"/>
</menu>

The flash random function is set as follow:


imageToLoad = Math.floor(Math.random()*(totalImageNum.length));

I would like to convert the Math part to a new Var that would generate a number that matches my 2 conditions.

Any idea?

the lazy way is to stick a variable into an array and check the array… theres a tut on the main page.

if its there don’t load, if it isn’t load

getting true random numbers seems difficult, I guess you would create a number 1,2,3 check it the last display was the same if not show else run the random number generator again

it may be a nightmare but I have discussed this before within living memory