Files
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

27 lines
662 B
Go

package common
import "math/rand"
// CanDeductByProbability 扣量指标的未完成度和今日时间进度递增 能扣量的概率递增 [0,100]
func CanDeductByProbability(probability float64) bool {
if probability <= 0 {
return false
}
if probability == 0 {
return false
}
if probability >= 1 {
return true //绝对扣量
}
canDeduct := probability > rand.Float64() //根据 probability 概率决定是否扣量
return canDeduct
}
// ConDeductionRatio 格式:%
func ConsumeDeductionRatio(optDividendRatio, dividendRatio float64) float64 {
if optDividendRatio == 0 {
return dividendRatio
}
return (1 - dividendRatio/optDividendRatio)
}