仿微信随机红包代码

发布时间:2020-07-28 17:20:55 作者:1255121660
来源:网络 阅读:3079

        public int num = 100;

        public int money = 2000;

        public int max = 88;

        public int min = 1;


        private void DataBing()

        {

            Random rd = new Random();

            List<int> list_ten = new List<int>();

            for (int i = 0; i < 10; i++)

            {

                int count=rd.Next(80, 88);

                money -= count;

                list_ten.Add(count);

            }

            List<int> list = new List<int>();

            //每个人先把最小金额拿到手

            for (var i = 0; i < 90; i++)

            {

                list.Add(min);

            }

            //计算还剩下多少钱

            money -= ((num-10) * min);

            //随机分配,直到钱花完

            while (money > 0)

            {

                //在0-99之间随机

                int idx = rd.Next(0, 90);

                if (list[idx] < max)

                {

                    list[idx] += 1;

                    money -= 1;

                }

            }

            for (int i = 0; i < list_ten.Count; i++)

            {

                list.Insert(i * i, list_ten[i]);

            }

            string a = "";

            int b = 0;

            for (int i = 0; i < list.Count; i++)

            {

                if (i % 10 == 0)

                {

                    a += "<br/>";

                }

                a += list[i] + ",";

                b += list[i];

            }

            Response.Write(a + "<br/>");

            Response.Write(b);

        }


推荐阅读:
  1. 模拟红包
  2. 使用PHP实现生成随机红包的算法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

微信红包 随机红包

上一篇:PHP 递归删除文件夹

下一篇:软件测试基础知识整理

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》