Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
30
pkg/utils/mt19937/bernoulli_distribution.go
Normal file
30
pkg/utils/mt19937/bernoulli_distribution.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package mt19937
|
||||
|
||||
import (
|
||||
"fiskerinc.com/modules/logger"
|
||||
)
|
||||
|
||||
type bernoulli_distribution struct {
|
||||
m_prob float64
|
||||
m_eng *MT19937
|
||||
}
|
||||
|
||||
func DistBernolli(eng *MT19937, prob float64) *bernoulli_distribution {
|
||||
if prob < 0 || prob > 1 {
|
||||
logger.Error().Msg("prob must be between 0 and 1")
|
||||
return nil
|
||||
}
|
||||
dist := &bernoulli_distribution{
|
||||
m_prob: prob,
|
||||
m_eng: eng,
|
||||
}
|
||||
return dist
|
||||
}
|
||||
|
||||
func (dist *bernoulli_distribution) Bool() bool {
|
||||
if dist.m_prob == 0 {
|
||||
return false
|
||||
} else {
|
||||
return float64(dist.m_eng.Random()) <= dist.m_prob*float64(^uint64(0))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user