1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-21 15:44:23 +00:00

Add Random.sample function

This commit is contained in:
Steffo 2024-04-16 02:18:47 +02:00
parent d222e8c066
commit 2286009079
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0

View file

@ -10,3 +10,12 @@ static var rng: RandomNumberGenerator = null:
return rng
set(value):
rng = value
static func sample(array: Array[Variant], imin = null, imax = null) -> Variant:
if imin == null:
imin = 0
if imax == null:
imax = len(array) - 1
var idx = rng.randi_range(imin, imax)
return array[idx]