Skip to content

Commit

Permalink
Replace hand rolled shuffle with rand.Shuffle
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed Jun 13, 2024
1 parent 38099de commit a082e3d
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions wallet/udb/txmined.go
Original file line number Diff line number Diff line change
Expand Up @@ -2360,21 +2360,6 @@ func randUint32n(n uint32) uint32 {
}
}

func shuffle(n int, swap func(i, j int)) {
if n < 0 {
panic("shuffle: negative n")
}
if int64(n) >= 1<<32 {
panic("shuffle: large n")
}

// Fisher-Yates shuffle: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
for i := uint32(0); i < uint32(n); i++ {
j := randUint32n(uint32(n)-i) + i
swap(int(i), int(j))
}
}

// UnspentOutputCount returns the number of mined unspent Credits (including
// those spent by unmined transactions).
func (s *Store) UnspentOutputCount(dbtx walletdb.ReadTx) int {
Expand Down Expand Up @@ -3257,7 +3242,7 @@ func (s *Store) MakeInputSource(dbtx walletdb.ReadTx, account uint32, minConf,
return nil, err
}
}
shuffle(len(remainingKeys), func(i, j int) {
rand.Shuffle(len(remainingKeys), func(i, j int) {
remainingKeys[i], remainingKeys[j] = remainingKeys[j], remainingKeys[i]
})
}
Expand Down

0 comments on commit a082e3d

Please sign in to comment.