Picking a random number from a list
#5

Quote:
Originally Posted by Backwardsman97
Посмотреть сообщение
The way I did this, like if you had to pick a random player id, was to store all of the possible choices in an array and then pick randomly from the array size. Maybe like this.

pawn Код:
new playerlist[MAX_PLAYERS],
    size;  // Maybe this is uneccessary and you could use sizeof

for(new i; i<MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i))
    {
        playerlist[size] = i;
        size++;
    }
}

new rand = playerlist[random(size) + 1];
Something like that I think.

Edit : Too slow...
Thanks for trying but doesn't really seem like what I want..
Reply


Messages In This Thread
Picking a random number from a list - by Jack_Leslie - 13.07.2011, 05:36
Re: Picking a random number from a list - by cessil - 13.07.2011, 05:43
Re: Picking a random number from a list - by Jack_Leslie - 13.07.2011, 05:44
Re: Picking a random number from a list - by Backwardsman97 - 13.07.2011, 05:44
Re: Picking a random number from a list - by Jack_Leslie - 13.07.2011, 05:46
Re: Picking a random number from a list - by cessil - 13.07.2011, 05:50
Re: Picking a random number from a list - by Bakr - 13.07.2011, 05:53
Re: Picking a random number from a list - by Pghpunkid - 13.07.2011, 06:00
Re: Picking a random number from a list - by Steven82 - 13.07.2011, 06:16
Re: Picking a random number from a list - by PrawkC - 13.07.2011, 06:21

Forum Jump:


Users browsing this thread: 2 Guest(s)