# Ethereum Lottery based on XOR-Distance

I was looking into the routing of the SAFEnetwork by Maidsafe. They use bitwise XOR to calculate the distance between 2 nodes. It’s a mathematical calculation which insures you’re almost get random connections around the globe.
When thinking about a lottery on Ethereum, let’s say 20.000 users send ETH to a lottery-contract. After 10.000 blocks there will be a winner. How do we know who has won? We need randomness! So here’s the trick to do that:

All addresses on Ethereum are already random. So the contract calculates the XOR-distance between the Hash of the last block and the 20.000 addresses who sent money to the contract to play the lottery. All people have to send the same amount of money (let’s say 1 ETH) and the contract will send the price to the address that’s closest to the Hash of the last block (random) and the address (random) based on XOR-Distance. What do you think?

Seems sound. Have you suggested it to them?

Yup, but only on the Reddit link above. It now has over 8 reactions by people. Some warn that miners could mine for their own profit, creating the hash in a way that they are closest to it. Others say that you need way to much hash-power to do so.

Actually, you can make a lottery so that you can calculate how much hashing power the miner will need.
Here’s the one I like:
sha3(block.hash, message.sender) < D
If D is 2256 / N, then the miner or pool has to mine at NX difficulty in order to attack the lottery. So if you make N=100000, as long as the reward for winning the lottery is less than the block reward for mining 100000 blocks you are financially secure.