From 5fe4ba1d1fd4b3e3d9ad6d4a77c2594e8f4df6c2 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 26 Mar 2024 12:58:03 +0800 Subject: [PATCH] 1 --- metatable.go | 8 ++++++++ 1 file changed, 8 insertions(+) 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()