# Tip: Randomize the contents of an Array

**URL:** <https://forum.kirupa.com/t/tip-randomize-the-contents-of-an-array/305150>\
**Category:** flash\
**Created:** [February 19, 2010, 9:09pm UTC](https://forum.kirupa.com/t/tip-randomize-the-contents-of-an-array/305150 "2010-02-19T21:09:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arosemena](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@arosemena](https://forum.kirupa.com/u/arosemena)\
**Post date:** [February 19, 2010, 9:09pm UTC](https://forum.kirupa.com/t/tip-randomize-the-contents-of-an-array/305150/1 "2010-02-19T21:09:14Z")

</div>

just wanted to share this, some months ago i was looking all over the web for an array content randomizer and found none, yesterday i was reading a book about AS3 and after finishing the arrays chapters tough of this:

```auto
function Random(target:Array):Array
{
	var tar1:Array = target;
	var tar2:Array = new Array();
	for(var i:int = 0; i < tar1.length; i++)
	{
		var selecter:int = Math.random() * 10;
		if(selecter >= 5)
                      {
                            tar2.push(tar1*);
                      }
		else
                      {
                            tar2.unshift(tar1*);
                      }
	}
	return tar2;
}

```

its a function that receives an array and return the received array scrambled, could be used like this

myArray = Random(myArray);

that would scramble the var myArray

(-:
