在运行时计算百分比时计、百分比

2023-09-11 05:40:31 作者:心傲;

我有这个问题,我有审核我的transtactions百分比。

I have this problem where I have to "audit" a percent of my transtactions.

如果是百分之100我必须审核所有这些,如果是0我要跳过所有这些,如果50%我要检讨的一半等。

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.

我想是:

audit = 100/percent

因此​​,如果百分比为50

So if percent is 50

audit = 100 / 50 ( which is 2 )

所以,我必须审计1,并跳过1审核1,并跳过1。

So I have to audit 1 and skip 1 audit 1 and skip 1 ..

如果是30

审计=三十〇分之一百(3.3)

audit = 100 / 30 ( 3.3 )

我的审计2和跳过第三。

I audit 2 and skip the third.

问题

我有问题的数字超过50%(如75%),因为它给了我1.333,...

I'm having problems with numbers beyond 50% ( like 75% ) because it gives me 1.333, ...

在将正确的算法知道有多少审计,因为他们去......我也有问题0(因除以0:P),但我有固定的已经,并与100等

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.

任何建议大大AP preciated。

Any suggestion is greatly appreciated.

推荐答案

为什么不去做它随机。对于每个事务,选择一个随机数0到100之间如果该数量小于你的百分数,则审计事务。如果该数字大于你的百分比,那就不要。我不知道这是否符合你的要求,但在较长的时间段,你将有权百分比审核。

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.

如果您需要确切的跳过2,审核,请跳到2审核合一的算法类型,你可能有运气适配的线条绘制算法。

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.