Files
youlegames/codes/games/server/games/gamehall/class.util.js
2026-02-04 23:47:45 +08:00

122 lines
2.8 KiB
JavaScript

/*
bingo
*/
Math.seed = 5;
Math.seededRandom = function(max, min) {
max = max || 1;
min = min || 0;
Math.seed = (Math.seed * 9301 + 49297) % 233280;
var rnd = Math.seed / 233280.0;
return Math.round(min + rnd * (max - min));
}
var bingo_Util = bingo_Util || {};
//从列表中随机出n个数字(不重复)
bingo_Util.randomFromList = function(n,_list){
var list = [].concat(_list);
if(n>list.length){
return [];
}
var result = [];
for(var i=0;i<n;i++){
var idx = ifast_random(list.length);
// var idx = Math.seededRandom(list.length,0) - 1;
result.push(list[idx]);
list.splice(idx,1);
}
//return result;
return bingo_Util.orderList(result,true);
}
//排序是否从小到大
bingo_Util.orderList = function(_list,_bTemp){
var _listTemp = [].concat(_list);
if (_listTemp){
for (var i = 0; i < _listTemp.length; i++) {
for (var j = i + 1; j < _listTemp.length; j++) {
switch(_bTemp){
case true:
if (_listTemp[i] > _listTemp[j]) {
var tmp = _listTemp[j];
_listTemp[j] = _listTemp[i];
_listTemp[i] = tmp;
}
break;
case false:
if (_listTemp[i] < _listTemp[j]) {
var tmp = _listTemp[j];
_listTemp[j] = _listTemp[i];
_listTemp[i] = tmp;
}
break;
}
}
}
}
return _listTemp;
}
//从_list2中找出匹配_list1的位置
bingo_Util.getMatchIndex = function(in_list1,in_list2){
var _list1 = [].concat(in_list1);
var _list2 = [].concat(in_list2);
var result=[];
for(var i=0;i<_list1.length;i++){
var findIndex = _list2.indexOf(_list1[i]);
if(findIndex>-1){
result.push(findIndex);
}
}
return result;
}
//从_list2中找出匹配_list1的数量
bingo_Util.getMatchCount = function(in_list1,in_list2){
var _list1 = [].concat(in_list1);
var _list2 = [].concat(in_list2);
var rValue = 0;
for(var i=0;i<_list1.length;i++){
var findIndex = _list2.indexOf(_list1[i]);
if(findIndex>-1){
rValue++;
}
}
return rValue;
}
//从_list1中删除与_list2相同相同的元素
bingo_Util.filterArray = function(in_list1,in_list2){
var _list1 = [].concat(in_list1);
var _list2 = [].concat(in_list2);
var arrtemp = _list1;
for(var i=0;i<_list2.length;i++){
arrtemp = arrtemp.filter(function(element,index,array){
return element != _list2[i];
});
}
return arrtemp;
}
//生成初始化值一致长度确定的数组
bingo_Util.createArray = function(_length,_value){
var returnValue = new Array(_length);
for(var i=0;i<returnValue.length;i++){
returnValue[i] = _value;
}
return returnValue;
}
//将毫秒转化为分秒
bingo_Util.convertToMntSed = function(mss){
var seconds = Math.ceil((mss % (1000 * 60)) / 1000);
//var minutes = Math.ceil((mss / (1000 * 60 )));
var minutes = Math.floor(Math.floor(mss / 1000)/60);
return [minutes,seconds];
}
function ifast_random(b) {
return parseInt(Math.random() * b);
}