You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I didn't really get your question,
But you might be confused in this line, I guess "We want our DNA to only be 16 digits long (remember our dnaModulus?). So the second line of code should return the above value modulus (%) dnaModulus."
I will explain:
keccak256 return 32 bytes (i.e. 32*8 = 256 bits), so we get value ranging from 0 to (2^56) -1, which is about 17 digits large I guess, calculate and count it.
But we want our dna to be of 16 digits. So we can just mod it with 10^16.
Take an example:
suppose we want to have 2 digits dna size.
and we have got a number eg. 155, which is 3 digits.
we can mod 155 by 10^2,
Note: 10^2 has 3 digits (100) but when we mod by 100, we get numbers ranging from 0 to 99, (where 100 is same as 0 in mod 100.)
Similary 10^16 has 17 digits, but when we mod by 10^17, we get numbers ranging from 0 to (10^16) - 1 (16 digits).
Activity
acharyayush commentedon Jun 10, 2025
I didn't really get your question,
But you might be confused in this line, I guess "We want our DNA to only be 16 digits long (remember our dnaModulus?). So the second line of code should return the above value modulus (%) dnaModulus."
I will explain:
keccak256 return 32 bytes (i.e. 32*8 = 256 bits), so we get value ranging from 0 to (2^56) -1, which is about 17 digits large I guess, calculate and count it.
But we want our dna to be of 16 digits. So we can just mod it with 10^16.
Take an example:
suppose we want to have 2 digits dna size.
and we have got a number eg. 155, which is 3 digits.
we can mod 155 by 10^2,
Note: 10^2 has 3 digits (100) but when we mod by 100, we get numbers ranging from 0 to 99, (where 100 is same as 0 in mod 100.)
Similary 10^16 has 17 digits, but when we mod by 10^17, we get numbers ranging from 0 to (10^16) - 1 (16 digits).
This way we get 16 digits dna.