Posts: 2,286
Threads: 18
Joined: Jun 2010
The native random doesn't accept floats. You just mindfucked me, but I figured it out, anyway I scripted this, and it worked like a charm
Код:
stock Float:RandomEx(Float:max)
{
new Float:range = max;
new Float:num = range * random(32767)/32767;
return num;
}
And if you want minimum value param, try this:
Код:
stock Float:RandomEx(Float:min,Float:max)
{
new Float:range = max-min;
new Float:num = min+range * random(32767)/32767;
return num;
}
Posts: 2,286
Threads: 18
Joined: Jun 2010
Quote:
Originally Posted by ******
What's with all the extra variables?
pawn Код:
stock Float:frandom(Float:max) { return max * random(32768) / 32768.0; }
pawn Код:
stock Float:frandomex(Float:min, Float:max) { return min + (max - min) * random(32768) / 32768.0; }
Trust me, reduction like this is good in PAWN (as is the ".0") and the use of "32768" instead of "32767".
|
Mm'kay, though I only gave him the example function. And why is "32768" better than "32767" ? Because it's even?
Posts: 2,286
Threads: 18
Joined: Jun 2010
Quote:
Originally Posted by ******
Power of two.
|
Ah, yes, didn't even go through my mind lol
Posts: 2,286
Threads: 18
Joined: Jun 2010
Quote:
Originally Posted by nuriel8833
What do I need to put instead of the Float:frandomex?
|
That's your stock's name. Don't remove the float, but you can change the part after the Float: to whatever you like.
Posts: 2,286
Threads: 18
Joined: Jun 2010
Quote:
Originally Posted by nuriel8833
Sorry for doublepost,but theres a warning:
pawn Код:
warning 208: function with tag result used before definition, forcing reparse
Why?
|
Well, not sure, but what did you change in the code? Because it worked fine for me.