# Newbie random MC help

**URL:** <https://forum.kirupa.com/t/newbie-random-mc-help/19571>\
**Category:** Uncategorized\
**Created:** [April 29, 2003, 1:39pm UTC](https://forum.kirupa.com/t/newbie-random-mc-help/19571 "2003-04-29T13:39:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mogi](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@mogi](https://forum.kirupa.com/u/mogi)\
**Post date:** [April 29, 2003, 1:39pm UTC](https://forum.kirupa.com/t/newbie-random-mc-help/19571/1 "2003-04-29T13:39:42Z")

</div>

i’m trying to create some buttons as MCs that will load random imageMCs on release or rollover

i think i am supposed to use math random in some form with MCs but i have no idea how to execute the script for that

any ideas and advice would be appreciated

thanks in advance

mogi

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 29, 2003, 2:57pm UTC](https://forum.kirupa.com/t/newbie-random-mc-help/19571/2 "2003-04-29T14:57:22Z")

</div>

You could do it like this:

- name the imageMC’s: imageMC1, imageMC2, imageMC3 etc.
- on the button place something like this:

```auto

on(release){
  // if there are 3 imageMC's
  myTarget = Math.round(Math.random(2)+1);
  _root["imageMC"+myTarget].play(); 	
}

```

_Math.random(2)_ gives you a random value between 0 and 2  
_+1_ makes this a number between 1 and 3.  
_Math.round()_ rounds this value to the nearest integer, e.g. 2.132 will become 2

Note that in this case if _myTarget_ would equal 2, then _\_root[“imageMC”+myTarget].play()_ would tell _imageMC2_ to start playing.

Hope I’ve explained everything correctly =)
