需要一个公式来计算滚动
Need a formula to calculate roll
这是一个获取卷号的脚本(在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 滚动一个数字。每次都相同,直到更改哈希。
我需要将 5 个数字从 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 也可以。
尝试使用 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)
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)
这是一个获取卷号的脚本(在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 滚动一个数字。每次都相同,直到更改哈希。
我需要将 5 个数字从 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 也可以。
尝试使用 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)
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)