Skip to main content

RosalindDNA

RosalindDNA

Library used for combining uint256-encoded genes Named Rosalind after chemist Rosalind Franklin who discovered double-helix and significantly furthered our understanding of DNAs molecular structure.

GENERATION_MASK

uint256 GENERATION_MASK

breedDNASimple

function breedDNASimple(uint256[] parentsDNA, uint8[] genes, uint256 randomSeed) internal pure returns (uint256 childDNA)

Breeds multiple parents DNA, returning a new combined

NameTypeDescription
parentsDNAuint256[]N different parent DNAs
genesuint8[]start indicies of each gene. First index should ALWAYS be 0. Using [0, 128] splits the DNA into two genes of equal length
randomSeeduint256random value to use for gene splicing
NameTypeDescription
childDNAuint256combined child DNA

breedDNAWithMutations

function breedDNAWithMutations(uint256[] parentsDNA, uint8[] genes, uint256 randomSeed, uint256[] mutationRates) internal pure returns (uint256 childDNA)

Breeds multiple parents DNA, returning a new combined DNA Allows for random mutations to occur, producing random bits instead.

NameTypeDescription
parentsDNAuint256[]N different parent DNAs
genesuint8[]start indicies of each gene. First index should ALWAYS be 0. Using [0, 128] splits the DNA into two genes of equal length
randomSeeduint256random value to use for gene splicing
mutationRatesuint256[]probability that a random gene is picked vs. mutated. A higher mutation rate means a higher probability of having a random gene. The mutation rate m is a probability of m/(2^256-1) or in other words the probability that geneRandomnessSeed <= m. We therefore assign a mutated gene at the following rates according to m: 0 = 000... => 0% 2^254-1 = 001... => 25% 2^255-1 = 011... => 50% 2^255 + 2^254 -1 => 75% 2^256-1 = 111... => 100% Always mutate Calculated probability as a function: 1/2^(256-m)
NameTypeDescription
childDNAuint256combined child DNA with mutations occuring.

generateMutations

function generateMutations(uint256 dna, uint8[] genes, uint256 randomSeed, uint256[] mutationRates) internal pure returns (uint256 mutatedDNA)

Mutates encoded DNA

NameTypeDescription
dnauint256existing DNA to mutate
genesuint8[]start indicies of each gene. First index should ALWAYS be 0. Using [0, 128] splits the DNA into two genes of equal length
randomSeeduint256random value to use for gene splicing
mutationRatesuint256[]probability that a random gene is picked vs. mutated. A higher mutation rate means a higher probability of having a random gene. The mutation rate m is a probability of m/(2^256-1) or in other words the probability that geneRandomnessSeed <= m. We therefore assign a mutated gene at the following rates according to m: 0 = 000... => 0% 2^254-1 = 001... => 25% 2^255-1 = 011... => 50% 2^255 + 2^254 -1 => 75% 2^256-1 = 111... => 100% Always mutate Calculated probability as a function: 1/2^(256-m)
NameTypeDescription
mutatedDNAuint256combined child DNA with mutations occuring.

setGenCount

function setGenCount(uint256 child, uint256[] parentsDNA) internal pure returns (uint256)

Sets an offsprings generation (increases max parent +1)

NameTypeDescription
childuint256child dna
parentsDNAuint256[]array of parent dna

getGenCount

function getGenCount(uint256 child) internal pure returns (uint8)

Gets the generation for a specimen

NameTypeDescription
childuint256child dna to read specimen age

get256Bitmask

function get256Bitmask(uint16 startBit, uint16 endBit) internal pure returns (uint256 bitMask)

Generates a 256-bit bitmask from startBit:endBit

NameTypeDescription
startBituint16beginning of mask
endBituint16end of mask
NameTypeDescription
bitMaskuint256combined bitmask