Fairness
Dice Fairness
We do not want you to just believe our word when it comes to security. Instead, we are going to explain how we guarantee the fairness of each roll.
Randomization in a nutshell
Our members can verify their bets anytime they want. For this, they should deduce a roll number.
If you add a third element – Nonce – to the pair of Client Seed and Server Seed, you’ll be able to deduce the bet’s result. Sure, if you reveal your results ahead of time, it would ruin the whole process. Therefore we use SHA-256 hash to hide your Server Seed temporarily. Each Seed is revealed after the last randomization took place. This provides our users with the possibility to verify their rolls transparently.
How the roll numbers are calculated
The rules of the game stipulate that we need to know the roll number. To receive it, we should make some calculations. Combine your bet number, Server, and Client Seeds. As a result, we get a figure between 0 and 9,999.
This is how it works:
combination = Server Seed + Client Seed + Nonce
Further, we need a 128-character hex string using the SHA-512 hash:
hash = SHA512(combination)
At this point, we convert 5 characters of that hash to a so-called decimal number. Then, three scenarios are possible. If it is equal to a million or more, we continue the same using the next 5 characters. It happens up to 25 times. If none of these trials gave a result of less than a million, the last 3 characters will be converted to your roll number. In the opposite case, we divide it by 10K and consider your roll outcome.
How the code looks like
Use our online verifier or take a look at the code example to see how we verify our bet:
function getRoll(serverSeed, clientSeed, nonce) {
var hash = sha512(serverSeed + clientSeed + nonce);
var index = 0;
do {
var lucky = parseInt(hash.substr(index, 5), 16);
index += 5;
} while (lucky >= 1000000);
return lucky % 10000;
}
Fairness of the Lottery
We know how much you want to play at fair gaming sites. To convince you that DuckDice is trustworthy, we are going to explain how our provably fair mechanism works.
Randomization in a nutshell
To make the whole process fair, all numbers should be chosen blindly. Server Seed plays an important role here. We generate it when the sale of tickets starts and keep hidden till the end of sales.
Since the moment when all tickets are sold, Target Block should be used as Client Seed. For this, we fit the Stop Block of XRP in the following formula:
Stop block + 20 blocks
After the sales are done, our members can verify the fairness of the Lottery. For this, one needs to download a file that contains information about all tickets.
The draw starts when we write the hash down in Client Seed. Then the draw finishes and we provide our players with a link by an independent party. A person who follows this link can find all numbers and check fairness.
How the Lottery numbers are calculated
According to the Lottery rules, a number between 1 and 36 should be generated. The needed number is basically a combination of the Lottery Nonce, Server Seed, and Client Seed:
combination = Server Seed + Client Seed + Nonce
At this stage, we should calculate this combination’s SHA-512 hash:
hash = SHA512(combination)
Now we need to convert three characters at the beginning of that hash to a decimal number. As a result, this number is going to range from from 0 to 4095 (16 ^ 3 - 1). Our outcome should be equal to 1/36 of that number. If this calculation is impossible, we complete the same operations with the following 3 characters of the hash. The maximum possible number of such calculations is 42.
The last 2 characters can be converted to a number in case if we used all trials and did not found them successful.
What the code is
To verify the Lottery’s results, we use the formula, shown below. Otherwise, you can use our online calculator.
function getNumber(serverSeed, clientSeed, nonce) {
var hash = sha512(serverSeed + clientSeed + nonce);
var index = 0;
var minNumber = 1;
var maxNumber = 36;
do {
var lucky = parseInt(hash.substr(index, 3), 16);
index += 3;
} while (lucky >= 4068);
return minNumber + (lucky % (maxNumber - minNumber + 1));
}
function getNumbers(serverSeed, clientSeed, nonce) {
var numbers = [];
var currentNonce = 0;
while (currentNonce < nonce) {
var number = getNumber(serverSeed, clientSeed, currentNonce++);
if (-1 === numbers.indexOf(number)) {
numbers.push(number);
}
}
return numbers;
}