Return to Snippet

Revision: 35404
at November 7, 2010 11:51 by jaredyeo


Updated Code
function fRandomize(vArray : Array) : void
{
	var i : int;
	var j : int;

	for (i = 0; i < vArray.length - 1; i++)
	{
		j = i + Math.floor(Math.random() * (vArray.length - i));
		if (j != i)
			fSwap(vArray, i, j);
	}
}

function fSwap(vArray : Array, i : uint, j : uint) : void
{
	var t : *;

	t = vArray[i];
	vArray[i] = vArray[j];
	vArray[j] = t;
}

Revision: 35403
at November 7, 2010 11:50 by jaredyeo


Initial Code
function
fRandomize(
	vArray : Array
) : void
{
	var i : int;
	var j : int;

	for (i = 0; i < vArray.length - 1; i++)
	{
		j = i + Math.floor(Math.random() * (vArray.length - i));
		if (j != i)
			fSwap(vArray, i, j);
	}
}

function
fSwap(
	vArray : Array,
	i : uint,
	j : uint
) : void
{
	var t : *;

	t = vArray[i];
	vArray[i] = vArray[j];
	vArray[j] = t;
}

Initial URL
http://simplistika.com

Initial Description

                                

Initial Title
AS3 Randomize Array

Initial Tags
array

Initial Language
ActionScript 3