# the etherdice's detailed algorithm

according to this link about etherdice, the game needs both players provide a seed and combine them together as the input of a RNG(random number generator) to generate the dice number, but one problem is that the second player to upload the seed can have the ability to manipulate the output(I mean if the player knows about the RNG aogorithm, then he can search the seed space to find the one that benefit him), then how does the etherdice fix this problem?

## 1 Answer

The reason that this system is secure is that the two players must submit the hash of their random seeds before any betting takes place.

This is called non-malleable commitment, and it ensures that the players cannot change their seeds after they see all of the bets.

The inclusion of the blockhash, number, and timestamp is to ensure that even if the two seeders are colluding, they still can't affect the outcome unless they are also colluding with the miners.

There are still attack vectors, however. If the second person to reveal their seed does not like the outcome, they can choose not to reveal, and all of the money is refunded. This means they can take as many shots at the jackpot as they like, almost for free. This risk is low, however, since the operator of the site is that second person, so their reputation is at stake.

The site is provably fair, as long as the operator of the site is not colluding with the miners, which is a pretty big if...

For a totally decentralized, if less convinient version, see How can I securely generate a random number in my smart contract?

• what if we just have two players betting with other and there is no operator
– Wang
Commented Apr 10, 2016 at 2:27
• That's really easy. Just have each person independently come up with a random number `N`, concatenate it with their address, hash that, and send the hash along with the Ether to the contract. Once both players have bet, they each send the `N` to the contract, which verifies that the hash checks out, XORs or hashes them together, modulo two, and voila. Commented Apr 10, 2016 at 2:33
• That protocol can be extended to more than two players, of course, but there are some issues that arise where the last player has to put down a large security deposit Commented Apr 10, 2016 at 2:34
• There are other methods, too, like using the hash of the next Bitcoin block, transmitted through BTC Relay. Commented Apr 10, 2016 at 2:37