上菜
//混乱数组
function RandDataArray(data) {
//混乱准备
var dataTemp = [].concat(data);
var dataBuffer = [];
var length = dataTemp.length;
//混乱数据
var randCount = 0;
var position = 0;
do {
var randvalue = (((length - randCount) - 1) + 1);
position = Math.floor(Math.random() * randvalue);
dataBuffer.push(dataTemp[position]);
randCount++;
dataTemp[position] = dataTemp[length - randCount];
} while (randCount < length);
return dataBuffer;
}
//调用示例
var data = [1,2,3,4,5,6,7,8,9];
//混乱数组
var dataTemp = RandDataArray(data);
//输出数据
console.log("dataTemp=%s",JSON.stringify(dataTemp)); //输出数据:dataTemp=[3,4,1,7,2,5,9,8,6]