Skip to content
/ PRNG Public

Pseudo Random Number Generator for Botgaming project

Notifications You must be signed in to change notification settings

Botgaming/PRNG

Repository files navigation

PRNG

The Pseudo Random Number Generator (PRNG) is based on SHA-512 hash algorithm. Target pseudorandom value is calculated such way:

mod(int(sha512(serverSeed + clientSeed + playerWallet + nonce)), maxValue),

where

  • mod() – is a modulus operation (take a remainder from division on integer value maxValue);
  • maxValue - is a natural number, which is an upper bound of target pseudorandom number (in our application it is usually has no more 100 value);
  • int() – is a converting operation from hexadecimal string to integer value;
  • sha512() – is the SHA-512 hash calculation operation from the target string (serverSeed + clientSeed + playerWallet + nonce);
  • serverSeed – is a symbolic string, which is initialized with UUID (Universally Unique Identifier - 32 symbolic string without dashes) every first game cycle of the game session. Inside every successive game cycle in the same game session serverSeed will be initialized with sha512 function from previous serverSeed value (sha512(serverSeed)). Game session is considered as an interval between a player starts and ends a game. Game cycle is considered as distribution of card deck (decks) for card games and as one spin for slot games;
  • clientSeed - is an alphanumeric value with length from 4 to 32 symbols. This value may (or may not by a player desire) be changed on every pseudorandom number;
  • playerWallet - is an ethereum wallet address (20 bytes sequence which is represented as 42 symbolic hexadecimal string with 0x prefix). Example: 0x6a0fe2de79f61f2fd2f6caf528e4dec6ff8ef90e;
  • nonce - is a natural number, inside one game cycle it is unique and every next value is more than previous one (next value may equal to incremented previous one);

In general terms serverSeed is required to avoid a prediction of generator result from a player side, clientSeed - to exclude possibility of influence on open source generator result from a server, playerWallet provides uniqueness of generated sequences between different players (for multiple players games) through the same game session, nonce provides uniqueness of the generator bias (seed) through single game cycle in cases when clientSeed is not changed "enough".

PRNG implementation is contained in generators/generator.js file.

PRNG Testing

To test PRNG was used famous Random Number Test Suite which is called Dieharder Version 3.31.1 (Robert G. Brown (rgb), Dirk Eddelbuettel, David Bauer). The one implements main diehard and NIST tests. For more information about Dieharder see http://webhome.phy.duke.edu/~rgb/General/dieharder.php.
Test sequence for the suite was produced by the PRNG and contained 1 000 000 000 (one billion) unsigned integer values in binary format.
A module to generate test sequence is contained in generator-bin.js file.

PRNG Test Results

Test results of the Dieharder suite are represented in:
https://github.com/Botgaming/PRNG/blob/master/test-results/sequence.sha512.1000000000.4294967295.results.txt,
where it could be seen that all tests were passed.

About

Pseudo Random Number Generator for Botgaming project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published