Rate Problem.

03/22/2013 21:29 LordGragen.#1
hey guys i have a question i like to ask,

i am using the rate system in my project for example if this monster get killed he have 5% chance to drope the stone.

but some how the % system is not working proper. if i put 5% idk why it will drope the stone every 5 kills or maybe 7 or idk 4.

and should not drop to fast , here is the system i use

Code:
if (Name == "StoneStealer" && ServerBase.Kernel.Rate(5))
kernel.cs

Code:
public static Random Random = new Random();
kernel.cs

Code:
 public static bool Rate(int value)
        {
            return value > Random.Next() % 100;
        }
        public static bool Rate(int value, int discriminant)
        {
            return value > Random.Next() % discriminant;
        }
        public static bool Rate(ulong value)
        {
            return Rate((int)value);
03/22/2013 21:49 abdoumatrix#2
I'm not sure but could some thing like this help?

03/22/2013 22:16 pro4never#3
Try making an easily breakpointed method to calculate it and also ensure you are not running the percentage chance calculation more than once (some sources do a loop for item drops. You don't want to check for 5 percent droprate 5 times in a row or you'll have an issue)

Currently you have a poor way of handling things for a number of reasons.

#1: You can never use lower than 1 percent droprates (1 percent is pretty high... 100 mobs can be killed very quickly)
#2: The random value is always a whole number


Decimal calculations are more costly but here's a quick example that pops to mind.


Code:
public static bool percentSuccess(double chance)
{
var decChance = chance * .01;//convert to percentage chance to compare.
var randomVal = Random.NextDouble();
return decChance > randomVal;
}

Breakpoint the return statement to see if it returns results you would expect and then just streamline it to be

return (chance * .01) > Random.NextDouble();
03/23/2013 23:16 LordGragen.#4
thank you, gona try time to fix.
03/27/2013 07:15 LordGragen.#5
okay so here is what i did, please let me know if i am doing something wrong.
sorry my English is not perfect so i am trying to collect every detail as much as i can.


so on kernel i added

Code:
 public static bool percentSuccess(double chance)
        {
            var decChance = chance * .01;
            var randomVal = Random.NextDouble();
            return decChance > randomVal;
        }
and for monster

Code:
if (Name == "DeadWarrior" && ServerBase.Kernel.percentSuccess(5.0))
i started using 5.0 from 5 but idk if thats make any different. am i missing anything else.