getting array of random values from existing array

Function expects two parameters – existing array and number of values to be returned in returning array.

function getRandomFromArray(inArray, inCounter)
{
	var currentArray = inArray.slice();
	var newArray = new Array();
	for(var i = 0; i < inCounter; i++)
	{	
		var random = Math.floor(Math.random() * currentArray.length);
		var getValue = currentArray[ random ];
		newArray.push(getValue);
		currentArray.splice(random, 1);
	}

	return newArray;
}
Posted in code snippets, javascript | Leave a comment