Since chaincode has to be deterministic, is there any way to get same random number in all endorser nodes to implement something like a lottery? In Ethereum you can do something like that:
function random() private view returns (uint) {
return uint(keccak256(abi.encodePacked(block.difficulty, now, players)));
}
By using the blocknumber, timestampt, block difficulty, gas , etc...But you dont have that in Hyperledger Fabric.
You're quite correct that the deterministic nature of chaincode does cause issues with random numbers.
I'd look into doing this in one of two ways.
You can protect access to the set of generated numbers by various type of access control.