# Advanced Random Function

**URL:** <https://forum.kirupa.com/t/advanced-random-function/263661>\
**Category:** flash\
**Created:** [June 18, 2008, 2:21am UTC](https://forum.kirupa.com/t/advanced-random-function/263661 "2008-06-18T02:21:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![artriste](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@artriste](https://forum.kirupa.com/u/artriste)\
**Post date:** [June 18, 2008, 2:21am UTC](https://forum.kirupa.com/t/advanced-random-function/263661/1 "2008-06-18T02:21:06Z")

</div>

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.

```auto

<?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:

```auto

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?

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [June 18, 2008, 8:59am UTC](https://forum.kirupa.com/t/advanced-random-function/263661/2 "2008-06-18T08:59:02Z")

</div>

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
