I have this problem where I have to "audit" a percent of my transtactions.
If percent is 100 I have to audit them all, if is 0 I have to skip them all and if 50% I have to review the half etc.
The problem ( or the opportunity ) is that I have to perform the check at runtime.
What I tried was:
audit = 100/percent
So if percent is 50
audit = 100 / 50 ( which is 2 )
So I have to audit 1 and skip 1 audit 1 and skip 1 ..
If is 30
audit = 100 / 30 ( 3.3 )
I audit 2 and skip the third.
Question
I'm having problems with numbers beyond 50% ( like 75% ) because it gives me 1.333, ...
When would be the correct algorithm to know how many to audit as they go?... I also have problems with 0 ( due to division by 0 :P ) but I have fixed that already, and with 100 etc.
Any suggestion is greatly appreciated.
First: work out the difference (increase) between the two numbers you are comparing. Then: divide the increase by the original number and multiply the answer by 100. % increase = Increase ÷ Original Number × 100.
Find the percentage of one number in relation to another with the formula Percentage = (number you want to find the percentage for ÷ total) × 100. Move the decimal point two places to the right to convert from a decimal to a percentage, and two places to the left to convert from a percentage to a decimal.
Why not do it randomly. For each transaction, pick a random number between 0 and 100. If that number is less than your "percent", then audit the transaction. If the number is greater than your "percent", then don't. I don't know if this satisfies your requirements, but over an extended period of time, you will have the right percentage audited.
If you need an exact "skip 2, audit one, skip 2 audit one" type of algorithm, you'll likely have luck adapting a line-drawing algorithm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With