75% 的时间显示广告
75% 的情况下我都在尝试找到一种展示广告的方法。我目前有一个从 1 到 100 之间选择的随机数。如果随机数出现在 1 到 75 之间,我会显示 AD。有没有更好的方法来实现这个
I am trying to figure out a way to show an advertisement 75% of the time. I currently have a random number that is selected from 1 to 100. if the random number occurs between 1 and 75 I show the AD. Is there a better way to implement this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过这种方法,您可能将在 75% 的时间内展示广告。如果您希望严格达到 75%,则可以使用计数器。
With this approach you're probably going to display the ad 75% of the time. If you want it strictly 75%, you can use a counter.
您可以选择 1 到 4 之间的数字,如果是 1 到 3,则展示广告。 :) 但除此之外,没有。您有什么问题吗?
You could select a number between 1 and 4, and if it's 1 through 3 then show the ad. :) But otherwise, no. What are you having problems with?
您永远无法在 75% 的情况下准确地显示添加,因为为了确定 75% 的内容,您需要知道该值(在您的情况下为显示数量)。但如果您知道显示的数量,那么您过去一定已经显示过添加;)希望它有意义。
你正在做的事情很好;该添加将以 75% 的概率在每个显示器上显示。
You'll never be able to display an add exactly 75% of the time because, in order to determine 75% of something you need to know that value (in your case the number of displays). But if you know the number of displays then you must have shown the add in the past ;) Hope it makes sense.
What you are doing is fine; the add will be displayed with a probability of 75% on each display.