Created
November 21, 2021 20:21
-
-
Save joselvelez/782c3dcf09964f655ee5e60ed5a44906 to your computer and use it in GitHub Desktop.
Solidity pseudo random generator, for testing purposes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract PseudoRandom { | |
function abiEncode(string memory stringInput) public view returns (bytes memory) { | |
return abi.encode(stringInput, msg.sender, block.timestamp); | |
} | |
function kHash(bytes memory bytesInput) public pure returns (uint) { | |
return uint(keccak256(bytesInput)); | |
} | |
function random(string memory input, uint arrayLength) public view returns (uint) { | |
bytes memory abiEncodeOutput = abiEncode(input); | |
uint kHashOutput = kHash(abiEncodeOutput); | |
return kHashOutput % arrayLength; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment