In my RPG battle engine, I want there to be an Accurary stat and the higher the Accuracy, the greater the chance of an attack hitting. I am trying to make it random so that the user does not know exactly what's going to happen, but not too random to the point where the user doesn't have a clue.
I was thinking of making a function for attacking and at the beginning, have it check to see if the attack will hit by choosing between numbers (on a sort of PH base scale [1 -14] for laughs and gigles) that I define like so:
PSUEDO CODE:
If Accuracy = 5
Numbers to choose from are 2,4,8,9
Choose a random number (either 2,4,8,or 9)
If number is > 7 then attack hits
If number is < 7 then attack misses
endif
this will be like a 2/4 or 50 % chance of hitting. theoretically, half the time the user will miss and half the time he will hit.
as experience grows, the amount of numbers above seven will grow
If ACC is 6
Numbers to choose from are 2,4,8,9,10
Choose a random number (either 2,4,8,9,or 10)
If number is > 7 then attack hits
If number is < 7 then attack misses
endif
this will be like a 3/5 or 60% chance of hitting. theoretically, 40% of the time the user will miss and 60% of the time he will hit.
How would you guys go about choosing a random number between specific numbers that are previously defined that are not necessarily consecutive or chronological?