# Go To Random Frame

**URL:** <https://forum.kirupa.com/t/go-to-random-frame/321175>\
**Category:** flash\
**Created:** [April 12, 2011, 3:38pm UTC](https://forum.kirupa.com/t/go-to-random-frame/321175 "2011-04-12T15:38:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaelchandler](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@michaelchandler](https://forum.kirupa.com/u/michaelchandler)\
**Post date:** [April 12, 2011, 3:38pm UTC](https://forum.kirupa.com/t/go-to-random-frame/321175/1 "2011-04-12T15:38:46Z")

</div>

I’m making a slideshow that plays the different slides at random. I have a movieclip named _products_ that will have a different image on each of the 19 frames, and a code on the main timeline that changes the frames of the movie clip.  
I’m having a little issue with this code.

At first I used:

```auto
_root.products.gotoAndStop(random(19));

```

But I kept having one image show up two and sometimes three times in a row. So I tried making something up myself that went like this:

```auto
//Declaring my variables frm(Frame) and rfrm(Random Frame)
var frm:Number = 0;
var rfrm:Number = 0;
var rfrm2:Number = 0;
//giving the frames their values.
frm = _root.products.currentframe;
rfrm = (random(19));
rfrm2 = (random(19));
//Make the random frame not be the same as the last one.
if (frm=rfrm) {
	rfrm = (random(19));
	_root.products.gotoAndPlay("na");
} else {
	_root.products.gotoAndStop(rfrm);
}
//asign new values to variables
frm = _root.products.currentframe;
rfrm = (random(19));

```

I know it’s not perfect by any means, and it still gets the same image twice in a row sometimes, but never three.

Can can I improve this? I know that this is more of a logic problem than actually knowing the right code. I just can’t think of the solution. :upset:
