More efficient way of doing this?
#1

pawn Код:
forward PrivatePriceChange();
public PrivatePriceChange()
{
    new PrivateCountdown;
    PrivateCountdown = PrivateCount;

    while(PrivateCountdown >= 0)
    {
        if(random(2) == 0)
        {
            new PRICECHANGE;
            PRICECHANGE = random(10);
            PrivateS[PrivateCountdown] = PrivateS[PrivateCountdown] + PRICECHANGE;

        }

        else

        {

            new PRICECHANGE2;
            new PRICECHANGE3;
            PRICECHANGE2 = random(10);
            PRICECHANGE3 = PRICECHANGE2 - PRICECHANGE2 * 2;
            PrivateS[PrivateCountdown] = PrivateS[PrivateCountdown] + PRICECHANGE3;

        }

        printf("%d : %d",PrivateCountdown,PrivateS[PrivateCountdown]);
        PrivateCountdown--;

    }

}
The concerns I have is the first random for the positive or negative value, and my second concern is the whole else math for the negative Private value change (taking random (1-10) from the value.

What the function does is adds or takes up to 10 from the privatevalue ( doing house RealEstate and shit )
Reply
#2

That should work, but it can be done a lot easier:

new pricechange = random(20)
privates = privates + random - 10.

This will generate a random number between -10 and +10
And add (or substract if it's a negative number) it to privates
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)