What does this piece of code mean?

Can you tell me what this piece of solidity code means please?

uint number = uint(block.blockhash(block.number - 1)) % 37;

Thank you

Take care

Pierre

Well, `block.number` returns the current block number and the builtin function `block.blockhash`, or rather only `blockhash` expects a block number and returns the corresponding hash of this block.

So, this line of code takes the block hash of the previous block (block.number -1), converts this hash to a uint, and then performs a modulus 37 operation on it.

Example:

If the current block number/height would be `10634585`, we take the hash the previous block (with block height `10634584`) which is

`0x9f3b843db4c1e1f94ced0e101abcab6b912f27099fa8e684f252292b66e9311b`

.. converted to a uint and calculating modulo 37 gives us

`72022899595671774698588476995950590173605856445212735706703646854236147888411 % 37 = 7`

Hope this helps

• Thank you so much Aug 11, 2020 at 18:54
• You're welcome :) Aug 12, 2020 at 16:09