diff --git a/metatable.go b/metatable.go index 517fa73..9ead377 100644 --- a/metatable.go +++ b/metatable.go @@ -7,6 +7,7 @@ import ( "os" "q5" "reflect" + "math/rand" ) type MetaTable interface { @@ -56,6 +57,13 @@ func (this *RawMetaTable[T]) PreInit1() { func (this *RawMetaTable[T]) PostInit1() { } +func (this *RawMetaTable[T]) RandElement() *T { + if len(this.rawList) > 0 { + return this.rawList[rand.Intn(len(this.rawList))] + } + return nil +} + func (this *RawMetaTable[T]) ElementsInit(round int) { type RoundInit1 interface { Init1()