年末了,抽奖有关问题,请各位请问~速结贴
年末了,抽奖问题,请各位请教~~~~~~~~~~速结贴
有三个等级的奖品:A,B,C,几率分别是5%,20%,40%,每个用户登录上去都有一次抽奖资格,不知道下面该如何控制中奖情况呢,希望能提供下思路.
------解决方案--------------------
个人思路:
100个数,5个是1,20个是2,40个是3,其他的是0,打乱顺序之后从这里面随机抽取一个数a
然后生成个随机数b(范围1-3)
判断a和b是不是相等,如果相等则中奖,否则没中奖
------解决方案--------------------
随机数范围100(不能用Random,这个是伪随机)
0~4为A
5~24为B
25~64为C
其它为不中奖,结束
------解决方案--------------------
呵呵,如果你看不懂上面回复,那么这样把
你找个圆盘,那5个A,20个B,40个C,平均放到圆盘上,然后嘛就去转把,转到那个就是那个
------解决方案--------------------
有三个等级的奖品:A,B,C,几率分别是5%,20%,40%,每个用户登录上去都有一次抽奖资格,不知道下面该如何控制中奖情况呢,希望能提供下思路.
------解决方案--------------------
个人思路:
100个数,5个是1,20个是2,40个是3,其他的是0,打乱顺序之后从这里面随机抽取一个数a
然后生成个随机数b(范围1-3)
判断a和b是不是相等,如果相等则中奖,否则没中奖
------解决方案--------------------
随机数范围100(不能用Random,这个是伪随机)
0~4为A
5~24为B
25~64为C
其它为不中奖,结束
------解决方案--------------------
呵呵,如果你看不懂上面回复,那么这样把
你找个圆盘,那5个A,20个B,40个C,平均放到圆盘上,然后嘛就去转把,转到那个就是那个
------解决方案--------------------
public static class RealRandom
{
/// <summary>
/// 生成小于输入值绝对值的随机数
/// </summary>
/// <param name="NumSides"></param>
/// <returns></returns>
public static int Next(this int numSeeds)
{
numSeeds = Math.Abs(numSeeds);
if (numSeeds <= 1)
{
return 0;
}
int length = 4;
if (numSeeds <= byte.MaxValue)
{
length = 1;
}
else if (numSeeds <= short.MaxValue)
{
length = 2;
}
return Next(numSeeds, length);
}
private static int Next(int numSeeds, int length)
{
// Create a byte array to hold the random value.
byte[] buffer = new byte[length];
// Create a new instance of the RNGCryptoServiceProvider.
System.Security.Cryptography.RNGCryptoServiceProvider Gen = new System.Security.Cryptography.RNGCryptoServiceProvider();