Skip to content

Instantly share code, notes, and snippets.

@niksmac
Created September 8, 2016 02:14
Show Gist options
  • Save niksmac/ccd49a016878fc2932dc021349562d38 to your computer and use it in GitHub Desktop.
Save niksmac/ccd49a016878fc2932dc021349562d38 to your computer and use it in GitHub Desktop.
  1. Describe why it’s hard to code a random number generator in Ethereum. Summarize a few reasons why most intuitive solutions fail (eg. getting from block number)

  2. Describe an efficient approach to using off-chain data in an ethereum contract that minimizes the amount of trust required.

  3. Create an efficient solidity contract that includes the following functions:

  • sqrt(uint x) that returns the square root of a number to 2 decimal places
  • selectionsort(uint[] x) that uses the selection sort algorithm to return a sorted array
  • factorial(int x): returns the factorial of x using recursion
@sibizulu
Copy link

sibizulu commented Dec 4, 2016

Describe why it’s hard to code a random number generator in Ethereum. Summarize a few reasons why most intuitive solutions fail (eg. getting from block number)

Refer here

@niksmac
Copy link
Author

niksmac commented Dec 9, 2016

  1. The simple answer is No, you can't.
  • Most solution will not work because EVM will give you random-random numbers on each execution.
  • Using a blockhash, timestamp like any miner-defined value will also wont work because the miner can decide whether to publish the block or not.
  • Someone proposed a solution to use the Bitcoin Future Block hash as seed to the random function. The rationale is since the block reward is high the user might not opt to hide the block hash.
  • A DAO working as RNG of Ethereum randao

@niksmac
Copy link
Author

niksmac commented Dec 9, 2016

  1. We can use some decentralised file storage like IPFS to save the big files and keep the ipfshash to keep in the blockchain. Since hash will not change the data integrity will be there.
  • In ethereum there is Swarm Swarm: decentralized storage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment