diff --git a/metatable.go b/metatable.go index 9ead377..e64b4d9 100644 --- a/metatable.go +++ b/metatable.go @@ -102,6 +102,19 @@ func (this *IdMetaTable[T]) GetById(id int64) *T { } } +func (this *IdMetaTable[T]) RandElementExclude(cb func(*T) bool) *T { + if len(this.rawList) > 0 { + tryCount := 1 + for tryCount < 1000 { + meta := this.rawList[rand.Intn(len(this.rawList))] + if cb(meta) { + return meta + } + } + } + return nil +} + func (this *RawMetaTable[T]) Load() { if this.NoLoad { return