Ethereum : Need help understanding Cryptozombies Solidity Code.

Ethereum update: Need help understanding Cryptozombies Solidity Code.

In lesson 1, chapter 11 of cryptozombies, we have the following definitions and function:

uint dnaDigits = 16;
uint dnaModulus = 10 ** dnaDigits;

function _generateRandomDna(string _str) private view returns (uint) {
uint rand = uint(keccak256(_str));
return rand % dnaModulus;

The purpose of this function is to return a number that is exactly 16 digits long and I am not understanding how it does that.

I understand keccak256 and typecasting it into a unsigned integer. What I don’t is how the modulus of this uint “rand” and dnaModulus guarantees a number with 16 digits. Any help would be appreciated, thanks!

View the link

About Ethereum

Ethereum is a decentralized platform that runs smart contracts: applications that run exactly as programmed without any possibility of downtime, censorship, fraud or third-party interference.

Author: Omisebro

Score: 0

Don’t forget to share the post if you love it !

CryptoCurrency : How many developers here who created crypto tools?

Blockchain : Everipedia Launches First P2P Blockchain Encyclopedia