Skip to content

chapter 11 #763

Open
Open

Description

@Mrwicks00

image
Uint might be much than 16 digits using the keccak hash function to generate randomDna in chapter 11, i am confused!

Activity

  1. acharyayush commented on Jun 10, 2025

    @acharyayush

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions