Skip to content

Commit

Permalink
Attempt to fix codon Optimize rand usage
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasinsaurralde committed Nov 15, 2023
1 parent 9429846 commit 74b5fe7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions synthesis/codon/codon.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,11 @@ func Optimize(aminoAcids string, codonTable Table, randomState ...int) (string,
}

// weightedRand library insisted setting seed like this. Not sure what environmental side effects exist.
var randomSource *rand.Rand
if len(randomState) > 0 {
rand.Seed(int64(randomState[0]))
randomSource = rand.New(rand.NewSource(int64(randomState[0])))
} else {
rand.Seed(time.Now().UTC().UnixNano())
randomSource = rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
}

var codons strings.Builder
Expand All @@ -173,6 +174,7 @@ func Optimize(aminoAcids string, codonTable Table, randomState ...int) (string,
if !ok {
return "", invalidAminoAcidError{aminoAcid}
}
chooser.PickSource(randomSource)
codons.WriteString(chooser.Pick().(string))
}
return codons.String(), nil
Expand Down

0 comments on commit 74b5fe7

Please sign in to comment.