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 8febdb8 commit c5a01d0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions synthesis/codon/codon.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,13 @@ func (table *TranslationTable) OptimizeSequence(aminoAcids string, randomState .
}

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

var codons strings.Builder
codonChooser := table.Choosers
Expand All @@ -163,6 +165,7 @@ func (table *TranslationTable) OptimizeSequence(aminoAcids string, randomState .
if !ok {
return "", invalidAminoAcidError{aminoAcid}
}
chooser.PickSource(rand)

codons.WriteString(chooser.Pick().(string))
}
Expand Down

0 comments on commit c5a01d0

Please sign in to comment.