Choosing random player with player.GetAll()?

How would I choose one random player out of the entire list?

Thanks.


local randomply = player.GetAll()[math.random(1,#player.GetAll())]

Even easier:

[lua]
local randomply = table.Random(player.GetAll())
[/lua]

dude i didnt even know that function existed

Gbps because the player.GetAll() table has a sequential numerical index it would be better to use Entoros code. They both work but Entoros is just better PR for that type of thing.

Example of Entoros code.

[lua]
local rply = math.random(1, #player.GetAll()) – Yes we can use 1 because lua doesn’t start from 0 like traditional C#
local chosen = player.GetAll()[rply]
for i = 1, #player.GetAll() do
player.GetAll()*:PrintMessage(3, "The chosen one is "…chosen);
end
[/lua]

Would it just be easier with
[lua]local randomply = table.Random(ply.GetAll())[/lua]