Check This : https://sampforum.blast.hk/showthread.php?tid=183477
|
stock Float:frandnorm(const RAND_MAX = 32767)
{
//Using C's RAND_MAX constant, make a random number up to RAND_MAX and
//divide it by RAND_MAX, normalizing it (higher RAND_MAX = higher precision)
return Float:random(RAND_MAX) / Float:RAND_MAX;
}
stock Float:frand(const Float:max)
{
//Result will never exceed max, because we're multiplying a normalized (0 .. 1) value
//by the max (which will only ever give max or less)
return (frandnorm() * max);
}
stock Float:frandrange(const Float:min, const Float:max)
{
//Just offset range of random numbers by amount
return min + frand(max-min);
}
stock Float:frandnorm(const RAND_MAX = 32767)
{
return Float:random(RAND_MAX) / Float:RAND_MAX;
}
stock Float:frand(const Float:max)
{
return (frandnorm() * max);
}
main()
{
//Print out header
printf("0 to 20:\r\n-----");
//Generate 5 random numbers between the interval 0 to 20, and print them out!
for(new i = 0; i < 5; i++)
printf("%f", frand(20));
}
0 to 20: ----- 18.555864 11.637317 6.126285 10.887173 1.890316
new Float:MaxSize = 100.0; //This will be the largest size a fish can reach.
new Float:MinSize = 4.0; //This will be the smallest size a fish can reach.
new Float:RandSize = MinSize + float(random(floatround(MaxSize - MinSize) * 1000)) / 1000;
//Gives a random number between 4.0 (MinSize) and 100.0 (MaxSize). Results vary depending on the value of 'MaxSize' and 'MinSize'.