Random experience function gone crazy
#1

pawn Код:
stock minrand(min, max) return random(max - min) + min;
stock rand_exp(level)
{
    switch(level)
    {
        case 0: return minrand(200,100);
        case 1: return minrand(400,400);
        case 2: return minrand(200,300);
        case 3: return minrand(200,200);
        case 4: return minrand(200,150);
        case 5: return minrand(200,170);
        case 6: return minrand(200,160);
        case 7: return minrand(400,400);
        case 8: return minrand(200,140);
        case 9: return minrand(200,100);
        case 10: return minrand(200,400);
        case 11: return minrand(200,100);
        case 12: return minrand(200,100);
        case 13: return minrand(200,100);
        case 14: return minrand(200,100);
        case 15: return minrand(200,300);
        case 16: return minrand(200,300);
        case 17: return minrand(200,300);
        case 18: return minrand(200,190);
        case 19: return minrand(200,180);
        case 20: return minrand(200,300);
        case 21: return minrand(200,250);
        case 22: return minrand(200,250);
        case 23: return minrand(200,200);
        case 24: return minrand(200,100);
        case 25: return minrand(200,100);
        case 26: return minrand(200,100);
        case 27: return minrand(200,140);
        case 28: return minrand(200,160);
        case 29: return minrand(200,180);
        default: return 0;
    }
    return 1;
}
I got this function above which suppose to give random experience from 200 to X, and all i do is:

pawn Код:
playerDB[playerid][Exp] += rand_exp(playerDB[playerid][Level]);
And you know what it gives? It gives me a number like: xxxxxxxx its with 10 numbers omg, like above 100 million ,anyone knows the solution? o_O..
Reply
#2

return random(max - min) + min;
example input:
return random(500 -100) + 100;
random(400)+100;
returns any number between 100 and 500

example 2:
random(300-400) + 400;
random(-100)+400;
returns any number between 300 and 400

first impression: does random() support random negative values? I honestly do not know.
You can try buy creating a function with a random(-200) called. If it returns any large numbers then you know what the problem is.
in that case, your problem lies within the random negative.
If not, I wouldn't know
Reply
#3

Umh, so what's the solution?
Reply
#4

minrand(min, max)
not max min
so must be
case 0: return minrand(100,200); // number between 100 -200
...
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)