You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
344 B
26 lines
344 B
1 year ago
|
package mathx
|
||
|
|
||
|
import (
|
||
|
"math/rand"
|
||
|
"sync"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type Probe struct {
|
||
|
r *rand.Rand
|
||
|
lock sync.Mutex
|
||
|
}
|
||
|
|
||
|
func NewProbe() *Probe {
|
||
|
return &Probe{
|
||
|
r: rand.New(rand.NewSource(time.Now().UnixNano())),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (p *Probe) TrueOnProbe(probe float64) bool {
|
||
|
p.lock.Lock()
|
||
|
truth := p.r.Float64() < probe
|
||
|
p.lock.Unlock()
|
||
|
return truth
|
||
|
}
|