SA-MP Forums Archive
new random - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: new random (/showthread.php?tid=675791)



new random - Calinut200 - 21.05.2020

Helo!
If i have a code like that
PHP Code:
            new rand random(5);
            switch(
rand)
            {
                case 
0:
                {
                    new 
rand random(5);
                    {
                        and 
there others random
                    
}
                }
                case 
1:
                {
                    new 
rand random(5);
                    {
                        and 
there others random
                    
}
                }
                case 
2:
                {
                    new 
rand random(5);
                    {
                        and 
there others random
                    
}
                }
                case 
3:
                {
                    new 
rand random(5);
                    {
                        and 
there others random
                    
}
                }
                case 
4:
                {
                    new 
rand random(5);
                    {
                        and 
there others random
                    
}
                } 
I have how to optimize? Or to kill some random and still work?


Re: new random - Skimmer - 21.05.2020

No need to initialize random values within each case. Also the brackets are useless there.

pawn Code:
new rand = random(5);
switch(rand)
{
    case 0:
    {

    }
    case 1:
    {

    }
    case 2:
    {

    }
    case 3:
    {

    }
    case 4:
    {

    }
}



Re: new random - Calinut200 - 21.05.2020

Quote:
Originally Posted by Skimmer
View Post
No need to initialize random values within each case. Also the brackets are useless there.

pawn Code:
new rand = random(5);
switch(rand)
{
    case 0:
    {

    }
    case 1:
    {

    }
    case 2:
    {

    }
    case 3:
    {

    }
    case 4:
    {

    }
}
you not understand, in each case i have a'n random man


Re: new random - Adamoneoone - 21.05.2020

Code:
new rand = random(5);
{
and there others random
}
what are the point of having the brackets here? Does it even compile?
Anyway, if you're having a random number calculated everytime, why not do it once below the first random?
(i.e. having
Code:
new rand1 = random(5); 
new rand2 = random(5);
switch(rand1)
...
)
The code would be cleaner. Besides that, nothing to improve really.