The phrasing is a bit strange. You basically have to store a future blockhash number to be used, e.g., just the current blocknumber + 2. This blockhash is completely unknown at the time of the transaction, can only be influenced to some degree by Ethereum miners and thus provides a good-enough source of randomness for some protocols.
The approach would basically be:
- Store future block number in the last accepted bet.
- Inside the determine winner function evaluate the blockhash from the block number and compute the winner. Also handle the case if no one called this function for more than 256 blocks after the stored block number (see your other question: Blockhash Minus-256 Problem).
This is a simple example with a single function to gamble with ETH:
mapping (address => uint256) gameWeiValues;
mapping (address => uint256) blockHashesToBeUsed;
function playGame() public {
if (!blockHashesToBeUsed[msg.sender]) {
// first run, determine block hash to be used
blockHashesToBeUsed[msg.sender] = block.number + 2; // use 2 or more
gameWeiValues[msg.sender] = msg.value;
return;
}
uint256 randomNumber = uint256(blockhash(blockHashesToBeUsed[msg.sender]));
blockHashesToBeUsed[msg.sender] = 0;
gameWeiValues[msg.sender] = 0;
// randomNumber = 0 means expired blockhash, player looses
if (randomNumber != 0 || randomNumber % 2 == 0) {
uint256 winningAmount = gameWeiValues[msg.sender] * 2;
msg.sender.transfer(winningAmount);
}
}
See also https://soliditydeveloper.com/2019-06-23-randomness-blockchain.