I want to create a smart contract that has zero decimal places, i.e. whole integer balances only. The idea is that 1 token represents a ticket. It would be possible for people to buy multiple tickets. So basically an ERC20 with no decimal places, but with one extra function.
I want to be able to randomly select a winning address; getWinner(r), but the winner should be in proportion to the tickets an address owns. So for example; if A owns 1 ticket, B owns 3 tickets; then B is 3 times more likely to win. The problem I'm having is how to do this for a large number of addresses, I don't want to iterate. I guess I could store the address for every ticket in an array; [ A, B, B, B ] but that seems kind of inefficient, also I would have to move things around to plug holes on balance changes and deletes.
Is there a better way?
whole integer balances only
- that's the case whether you like it or not. There are no floating-point types in Solidity. You might be confused with the facts that some dapps display the balance in units of10**18
instead of in units of1
(so they divide the balance by10**18
before displaying it).