Created
April 14, 2018 07:49
-
-
Save nanomobile/727034ab5a942c5c3b62c3e71a7b343f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Random { | |
| /* Generates a random number from 0 to 100 based on the last block hash */ | |
| function randomGen(uint seed) constant returns (uint randomNumber) { | |
| return(uint(sha3(block.blockhash(block.number-1), seed ))%100); | |
| } | |
| /* generates a number from 0 to 2^n based on the last n blocks */ | |
| function multiBlockRandomGen(uint seed, uint size) constant returns (uint randomNumber) { | |
| uint n = 0; | |
| for (uint i = 0; i < size; i++){ | |
| if (uint(sha3(block.blockhash(block.number-i-1), seed ))%2==0) | |
| n += 2**i; | |
| } | |
| return n; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment