PHP code example of lucapuddu / php-provably-fair

1. Go to this page and download the library: Download lucapuddu/php-provably-fair library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lucapuddu / php-provably-fair example snippets


$algorithm = 'sha256';
$serverSeed = 'server seed';
$clientSeed = 'client seed';
$nonce = '1';
$min = 15;
$max = 96;

$output1 = hash_hmac($algorithm, "{$clientSeed}-{$nonce}", $serverSeed);
echo $output1; // 78ed9330f00055f15765cb141088f316d507204a745ad4800fd719fcbfca071a

$output2 = hexdec($output1) / (16 ** strlen($output1));
echo $output2; // 0.47237510628475

$result = $min + $output2 * ($max - $min);
echo $result; // 53.26238360906475‬

...
$output = $generator->roll();
echo $output;   //38.325308655221

// Change ProvablyFair state
$generator->setNonce('new nonce');

// Roll a new number
$output = $generator->roll();
echo $output;   //23.752100169784
 bash
composer 

...
$generator->verify(38.325308655221); // true