For a game I have implemented Chainlink VRF and a basic RNG for small games where the fee of Chainlink wouldn't make sense.
For the 3rd parameter to abi.encodePacked (some seed data? docs suck so not exactly sure), I pass all the public keys of players who have entered the game.
function basicRNG(address[] memory players) public view returns (uint256) {
return uint256(keccak256(abi.encodePacked(block.difficulty, block.timestamp, players)));
}
Since this is so much simpler than VRF I wonder are there drawbacks?:
- Could the random number generation somehow be manipulated? I would imagine the only way would be if the attacker was the only one who entered the game, because how could they control for an unknown public key affecting the random number?
Also bonus: any idea how gas-intensive passing a large array would be? Such as a 1000 player (1000 public key) game?