java SecureRandom nextInt()与nextGaussian() [英] java SecureRandom nextInt() vs nextGaussian()

查看:95
本文介绍了java SecureRandom nextInt()与nextGaussian()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题陈述:以1%到100%之间的X%折扣的幸运抽奖券奖励客户

假设平板是预先定义的(全部都是理论上的)

1%的折扣:90%的客户

10%的折扣:5%的客户

20% 折扣:3% 客户

100%的折扣:2%的客户

解决方案1:

对于每100位客户,我将使用良好的混洗算法预先填充大小为100的随机数组

90 1s(1 = 1%折扣)

5 10s(10 = 10%折扣)

3 20秒(20%折扣)

2 100s(100%折扣)

每当有客户光临时,我都会绘制random.nextInt(100)并获得折扣百分比

解决方案2:

使用SecureRandom的nextGaussian(),因为它是一种分布式随机算法.

如果我们要严格遵循%,哪个更准确?

请参考随机

谢谢.

解决方案

分布是统一的,因此在这种情况下,高斯分布的使用将受到限制.您需要均匀的分布.

我对您所面临的问题的理解是,您希望结果具有一定的分布(折扣太多可能会非常昂贵),但否则它应该是随机的,因为无法预测.如果您只是安排了100种可能的折扣,将其分类并循环使用,则这种安排是可以预见的.即使您每100个周期更改一次订单,也有关注的人可能会知道获得良好折扣的几率何时会比平常高或低(类似于二十一点中的计数卡).

我认为您需要的是水库采样算法.最简单的情况是,如果您知道总共有多少商品(比如有多少折扣券)以及是否有两个类别(赢家、输家).然后,可以按原样使用Wikipedia文章中的代码.这个问题似乎是因为涉及多个类别(100%,20%,10%,1%)的文献较少,并且不知道优惠券的总数(例如,如果是限时促销).我将继续寻找有关该主题的论文,但这是我的基本想法.

Problem statement: Reward a customer with lucky draw coupon of X% discount in between 1% to 100%

Assume that slabs are pre-defined ( all are theoretical)

1% discount : 90% customers

10% discount : 5% customers

20% discount : 3% customers

100% discount : 2% customers

Solution 1:

For every 100 customers, I will pre-populate a random array of size 100 with a good shuffling algorithm

90 1s ( 1 = 1% discount)

5 10s ( 10 = 10% discount)

3 20s ( 20% discount )

2 100s ( 100% discount)

Whenever a customer comes, I will draw random.nextInt(100) and get discount percentage

Solution 2:

Use nextGaussian() of SecureRandom since it is a distributed randomness algorithm.

Which one is more accurate if we want to follow the % strictly?

Refer to example 1 and 3 in Random

Thanks in advance.

解决方案

The distributions are uniform, so Gaussian distribution would be of limited use in this situation. Uniform distributions are what you need.

My understanding of the problem that you're facing is that you want the outcome to have a certain distribution (too many discounts could be very expensive) but otherwise it should be random as in unpredictable. If you just took an arrangment of the 100 possible discounts, sorted them, and used them in a cycle, the arrangement would be predictable. Even if you changed the order for each cycle of 100, someone paying attention might know when the odds of getting a good discount would be higher or lower than normal (sort of like counting cards in Blackjack).

What I think you need instead is a Reservoir Sampling algorithm. The easiest scenario is if you know how many items there will be altogether (how many discount coupons, say) and if there are two categories (winner, loser). Then the code in the Wikipedia article can be used as-is. The problem seems to have less literature with multiple categories (100%, 20%, 10%, 1%), and not knowing the full number of coupons (if it's a time-limited promotion, say). I'll keep looking for papers on the topic, but that's the general idea, I think.

这篇关于java SecureRandom nextInt()与nextGaussian()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆