2016-02-13 140 views
-1

这里是一个脚本,得到(在CSGODOUBLE使用)卷号:需要一个公式来计算卷

$server_seed = "39b7d32fcb743c244c569a56d6de4dc27577d6277d6cf155bdcba6d05befcb34"; 
$lotto = "0422262831"; 
$round_id = "1"; 
$hash = hash("sha256",$server_seed."-".$lotto."-".$round_id); 
$roll = hexdec(substr($hash,0,8)) % 15; 
echo "Round $round_id = $roll"; 

此辊从0的数14。一样每一次,直到所述散列是改变。

我需要滚动数字从0到4但他们不能重复。我需要使用相同的散列系统来完成它。

$hash = "FIRST"; 
Outcomes:0,3,1,2,4; 

$hash = "SECOND"; 
Outcomes:1,4,2,3,0; 

$hash = "THIRD"; 
Outcomes:2,0,1,3,4 

// etc. 

而且,这将是完美的得到JavaScript中的公式,但PHP一个工作了。

+0

我其实还没有尝试过任何东西,只是寻找建议.. – Nedas

+0

抱歉,但您的问题可能会被关闭。 StackOverflow是一个排除代码故障的工具,而不是教程。 – Jeff

+0

啊我明白了,对不起。 – Nedas

回答

0

尝试使用Array.prototype.slice()复制项目的原始阵列,Array.prototype.splice()从复制的数组,Math.floor()Math.random()检索项目,while

var arr = [0,1,2,3,4]; 
 
var res = []; 
 
var copy = arr.slice(0); 
 
while (copy.length) { 
 
    res.push(copy.splice(Math.floor(Math.random() * copy.length), 1)[0]); 
 
} 
 
document.write(res)

0

var arr = [0,1,2,3,4]; 
 
var res = []; 
 
var copy = arr.slice(0); 
 
while (copy.length) { 
 
    res.push(copy.splice(Math.floor(Math.random() * copy.length), 1)[0]); 
 
} 
 
document.write(res)

+0

添加到您的代码片段中的某些解释行将使您的答案更好。 –