首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

年末了,抽奖有关问题,请各位请问~速结贴

2013-02-15 
年末了,抽奖问题,请各位请教~~~~~~~~~~速结贴有三个等级的奖品:A,B,C,几率分别是5%,20%,40%,每个用户登录

年末了,抽奖问题,请各位请教~~~~~~~~~~速结贴
有三个等级的奖品: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();


            // Fill the array with a random value.  
            Gen.GetBytes(buffer);
            // Convert the byte to an uint value to make the modulus operation easier.  
            uint randomResult = 0x0;//这里用uint作为生成的随机数  
            for (int i = 0; i < length; i++)
            {
                randomResult 
[解决办法]
= ((uint)buffer[i] << ((length - 1 - i) * 8));
            }
            // Return the random number mod the number  
            // of sides.  The possible values are zero-based  
            return (int)(randomResult % numSeeds);
        }
    }

public class AAA
{
    public bool HasDone(string uid)
        {
            return false;//判断是否已经抽过奖
        }

        public void ABC(string uid)
        {
            if (!HasDone(uid))//没抽过奖
            {
                int rd = RealRandom.Next(100);
                if (rd < 5)
                {
                    //A
                }
                else if (rd < 25)
                {
                    //B
                }
                else if (rd < 65)
                {
                    //C
                }


                else
                {
                    //没中奖
                }
            }
        }
}


[解决办法]
一个可以设置中奖概率的抽奖程序 8L即可
关于抽奖概率的编程实现思路问题

热点排行