Sorry for the late reply.
Basically I don't see anything wrong with the code but we don't have all the code in that picture: please post the content of current.GetBonus("chanceToJam") function.
Until then my assumption is that Unity's RNG generator might be fucked meaning that it generates more numbers closed to 0 (could be a special case just for some type of processors).
Other than this, the code is unoptimized: the addition of chanceToJam each fucking time is retarded. I wonder why?
What is wrong with calculating each chance by itself? That's what random means.
There is nothing wrong with checking the chance-to-jam for each shoot, in fact that's the purpose of that code and what is needed.
The problem is that the code is calculating
the chance-to-jam threshold every-time a player/npc is shooting -> the threshold is the return of GetChanceToJam() function.
There is no need to compute the chance-to-jam each time you shoot because this threshold doesn't change between shoots (unless inXile implements weapon degradation).
And it's obvious that a sane implementation would save this threshold per avatar/npc and then update it only when change conditions are present: weapon was changed, new mod was applied or removed and so on.
But I guess you want them to use a table that is filled in advance, so it is "fair" and jams exactly 2 times in every 100 shots, if it's 2%?
This is actually the point of the entire discussion. Maybe there is a confusion on my side or not but imweasel stated something like that:
"5% chance to jam ≙ statiscally, 1 out of 20 shots will cause your gun to jam"
The fact is that the implemented code has nothing to do with what imweasel stated cause it just does the following:
- compute chance-to-jam threshold, which is redundant in my opinion irrelevant of run-time penalties,
- takes a random number in the 0 to 100 range,
- compares this to the threshold and return true/false depending on the comparison result.
It is pretty evident that this entire implementation depends on the RNG quality and that it doesn't implement a statistical model.
I have no strong personal preferences but a statistical model might be better for one reason -> reducing save scumming.
Basically with the current implementation, as long as you have 1% chance of opening a safe then you can save scum until you will open that safe.
But if a statistical model system was implemented like imweasel said then it would be impossible to open some safes because the model will dictate that you must have 2% percent of failures.
How this statistical mode is implemented is not really important. It can be done with lists or math formulas considering the past success rate or other factors. It really depends what the developer wants.