Pick 5 random numbers from array that cant be the same
#3

Quote:
Originally Posted by gamer_Z
Посмотреть сообщение
pawn Код:
stock Give5RandomNumbers(number,&A,&B,&C,&D,&E)
{
    new rand[5];// Create the variables

    rand[0] = random(number);// assign a random value to rand[0] with the max 'number'

    XXXA://declare a position

    rand[1] = random(number); // assign second number

    if(
        rand[0] == rand[1]// check if first value matches second value
    )
        goto XXXA;// if it matches it will go to our position back to pick a new random number
   
    XXXB://and so on....
   
    rand[2] = random(number);

    if(
        rand[0] == rand[2] ||
        rand[1] == rand[2]
    )
        goto XXXB;

    XXXC:
   
    rand[3] = random(number);

    if(
        rand[0] == rand[3] ||
        rand[1] == rand[3] ||
        rand[2] == rand[3]
    )
        goto XXXC;
       
    XXXD:
   
    rand[4] = random(number);

    if(
        rand[0] == rand[4] ||
        rand[1] == rand[4] ||
        rand[2] == rand[4] ||
        rand[3] == rand[4]
    )
        goto XXXD;

    A = rand[0];
    B = rand[1];
    C = rand[2];
    D = rand[3];
    E = rand[4];

    return 1;
}
I do not recommend to use this but this is an exmpale. I have written it now ;P But it should work.
if it stucks in a big loop it wil lag your server, if it stucks in a forever loop your server will need a restart.
Yeah could of done this but I really didn't want to make something this big.
Reply


Messages In This Thread
Pick 5 random numbers from array that cant be the same - by s1k - 23.03.2011, 20:48
Re: Pick 5 random numbers from array that cant be the same - by Gamer_Z - 23.03.2011, 20:58
Re: Pick 5 random numbers from array that cant be the same - by s1k - 23.03.2011, 21:14
Re: Pick 5 random numbers from array that cant be the same - by Gamer_Z - 23.03.2011, 21:15
Re: Pick 5 random numbers from array that cant be the same - by Vince - 23.03.2011, 21:19
Re: Pick 5 random numbers from array that cant be the same - by s1k - 23.03.2011, 21:32

Forum Jump:


Users browsing this thread: 3 Guest(s)