My thought is that we come up with a random number in one block and make it private so no one can see it. The timer will allow a few blocks to be mined and then the revealNumber function allows the secret number to be known and then generates another random number. I think this would eliminate the possibility for block manipulation? Is there any way that someone could see something that is private?
pragma solidity ^0.5.4;
contract SKYLotto {
uint256 private secretNumber;
uint256 public releasedNumber;
uint256 public time;
function randomGen() public {
secretNumber = uint(keccak256(abi.encodePacked(now, msg.sender))) % 10;
time = now + 30 seconds;
}
function revealNumber() public {
enter code here require(now > time);
releasedNumber = secretNumber;
randomGen();
}
}
make it private so no one can see it
- that won't work; the only reason to declare a state-variable private is to semantically emphasize that no one should want to see it. But if somebody decides that they do, for some reason, then they can. No way for you to prevent that, so don't count on it for security! – goodvibration Feb 13 '19 at 7:47