2016-02-13 60 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

添加到您的代碼片段中的某些解釋行將使您的答案更好。 –