# Optimising random choice code

**URL:** <https://forum.kirupa.com/t/optimising-random-choice-code/325731>\
**Category:** Uncategorized\
**Created:** [November 2, 2011, 10:35am UTC](https://forum.kirupa.com/t/optimising-random-choice-code/325731 "2011-11-02T10:35:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeancnicolas](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@jeancnicolas](https://forum.kirupa.com/u/jeancnicolas)\
**Post date:** [November 2, 2011, 10:35am UTC](https://forum.kirupa.com/t/optimising-random-choice-code/325731/1 "2011-11-02T10:35:23Z")

</div>

Hiya … I want to make some code that randomly selects functions and when its order has been completed, it then fires off another random function selection again, so I have a continous play automatically generated…\>  
what I have so far works … anyone else out there has any better ideas?

Why?! because when I export this test to iOS - it collapses and does not work …

```auto

var ON:Boolean = true;
var func_ary:Array = [one,two,three,four];

function one():void
{
    trace("1");
randomFunction();
}
function two():void
{
    trace("2");
randomFunction();
}
function three():void
{
    trace("3");
randomFunction();
}
function four():void
{
    trace("4");
randomFunction();
}

function randomFunction():void
{
    if (ON==true)
   {
    var rnum:uint = Math.random()*func_ary.length-1;
    func_ary[rnum]();
   }
}

randomFunction();

```
