Commit 84f61d6a authored by Dirk McCormick's avatar Dirk McCormick

refactor: move rand outside lock

parent 95de8551
package session
import (
"math"
"math/rand"
"sync"
"time"
......@@ -133,13 +134,15 @@ func (sw *sessionWants) LiveWants() []cid.Cid {
// RandomLiveWant returns a randomly selected live want
func (sw *sessionWants) RandomLiveWant() cid.Cid {
r := rand.Float64()
sw.RLock()
defer sw.RUnlock()
if len(sw.liveWants) == 0 {
return cid.Cid{}
}
i := rand.Intn(len(sw.liveWants))
i := math.Floor(r * float64(len(sw.liveWants)))
// picking a random live want
for k := range sw.liveWants {
if i == 0 {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment