mercredi 26 août 2015

java SecureRandom nextInt() vs nextGaussian()

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:

Find the total number of customers. call nextInt(customer count). For example, assume that there are 100 customers.

if nextInt() is in between

99-100 : 100% discount

96-98 : 20%

90 -95: 10%

1-89 : 1%

Solution 2:

Use nextGaussian() of SecureRandom since it is a distributed randomness algorithm. How to configure above range using Gaussian?

Which one is more accurate?

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire