21.06.2017, 03:03
Quote:
Select Random Player
PHP Code:
|
PHP Code:
new k = GetPlayerPoolSize(),T[k];
Now in your algorithm you are creating an array for nothing all we need is a random player id. What you now doing is creating an array of connected players and randomizing the index of that array and returning the value in that index.Which is clearly a bad method.
You can either use foreach and use it's own builtin Iter_Random function to get random players from the iterator Player or if you want to do without foreach either modify this function to supporting a cache like system.That means change the content of the array (static or global one) only when a change in number of connected player or their id occurred and return the random id.So that the same process of creating an array is not required in each overhead.