彩票验证
中奖号码是如何产生的?
Lottocryptos在其彩票中使用 "可证明的公平 "系统,以实现中奖号码生成的透明度。
中奖随机数生成的种子由四部分组成:
A - 随机数最高为128。
为了获得用于随机生成中奖号码的种子,需要遵循以下流程。
每个部分都用SHA512加密并连接起来。然后再次用SHA512加密,并将其字符转换为相应的ASCII值。用于生成随机数的种子就是这个值。
为了能够让随机数的生成变得更容易,我们需要对其进行加密。
为了能够进行所有被认为适当的检查,我们向用户提供了用于获得随机数的源代码和执行随机性测试的工具。
源代码
文件: classes/class.Random.php
PHP版本: 7.4.33
最后更新: 2022-九月-17 10:57:44 UTC
尺寸: 3231 字节
<?php
function Random_number($length){
$result = '';
//Generate random number.
for($i=0;$i<$length;$i++){
$result = $result.random_int(0,9);
}
//Remove leading zeros.
$result = ltrim($result,'0');
if($result == ''){
$result = 0;
}
return $result;
}
function Random_string_to_int($string){
$result = '';
//Count characters.
$length = strlen($string);
//Ord ->Convert a character to its ASCII decimal value.
for($i=0;$i<$length;$i++){
$result = $result.ord($string[$i]);
}
return $result;
}
function Random_int_to_string($number){
//Convert integer to string.
$result = number_format($number,0,'','');
return $result;
}
function Random_hash($data,$algo){
//Hash string with an algo.
$result = hash($algo,$data);
return $result;
}
function Random_basic_seed(){
$result = Random_number(128);
return $result;
}
function Random_gmp_winner_number($basic_seed,$player_seed,$n_tickets,$n_players){
$result = '';
//Convert integer to string.
$n_tickets = Random_int_to_string($n_tickets);
//Hash all the parts
$basic_seed = Random_hash($basic_seed,'sha512');
$player_seed = Random_hash($player_seed,'sha512');
$n_tickets_seed = Random_hash($n_tickets,'sha512');
$n_players_seed = Random_hash($n_players,'sha512');
//Join all parts and hash
$seed = Random_hash($basic_seed.$player_seed.$n_tickets_seed.$n_players_seed,'sha512');
//Convert letters to numbers.
$seed = Random_string_to_int($seed);
//Insert seed into number generator. Only integers.
gmp_random_seed($seed);
//Generate random number.
$value = gmp_random_range(1,$n_tickets);
//Convert GMP integer to string.
$result = gmp_strval($value);
return $result;
}
/*
//WINNER NUMBER
$basic_seed = Random_basic_seed();
$player_seed = 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16';//Transaction ID
$n_players = 1;
$n_tickets = 100000000;
echo Random_gmp_winner_number($basic_seed,$player_seed,$n_tickets,$n_players);
//RANDOMNESS TEST (Can be CPU intensive with more cycles / rounds)
$cycles = 1;
$runs = 1000;
$tickets = 5;
$player_seed = 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16';//Transaction ID
$players = 5;
$n_runs = 0;
$probs = 0;
$results = array();
$results_prob = array();
for($i=0;$i<$cycles;$i++){
for($k=0;$k<$runs;$k++){
$basic_seed = Random_basic_seed();
$number = Random_gmp_winner_number($basic_seed,$player_seed,$tickets,$players);
if(array_key_exists($number,$results)){
$results[$number]++;
}
else{
$results[$number] = 1;
}
}
}
ksort($results);?>
<table>
<thead>
<td>Number</td>
<td>Number of Times</td>
<td>Probability</td>
</thead><?php
foreach($results as $key => $value){
$n_runs += $value;
$x = number_format((($value * 100)/($cycles * $runs)),3);
$probs += $x;?>
<tr>
<td><?php echo $key;?></td>
<td><?php echo $value;?></td>
<td><?php echo $x.' %';?></td>
</tr><?php
} ?>
<tfoot>
<td>Total Numbers: <?php echo count($results);?></td>
<td>Total Runs: <?php echo $n_runs;?></td>
<td>Total Prob: <?php echo $probs.' %';?></td>
<tfoot>
</table><?php
*/
?>
随机性检验
2024-十月-15 04:09:22 UTC
|
||
---|---|---|
价值观 | 运行次数 | 可能性 |
1 | 213 | 21.300 % |
2 | 191 | 19.100 % |
3 | 204 | 20.400 % |
4 | 180 | 18.000 % |
5 | 212 | 21.200 % | 5 | 1000 | 100 % |