C# 模拟微信红包功能,三种算法

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp5{ class Program { static void Main(string[] ...
摘要由CSDN通过智能技术生成
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            #region   红包算法一
            Console.WriteLine("-----------------------------------红包算法一---------------------");
            //初始化要发起的红包基础数据
            double total = 100;
            int num = 50;
            double min = 0.01;
            string temp;
            bool flag = false;
            Console.WriteLine(string.Format("是否需要自定义红包金额和数量(默认{0}元/{1}人)Y/N:", total, num));
            temp = Console.ReadLine();
            if (temp.Trim().ToLower().Equals("y") || temp.Trim().ToLower().Equals("yes"))
            {
                Console.WriteLine("请输入你要发起的红包金额:");
                do
                {
                    temp = Console.ReadLine();
                    flag = double.TryParse(temp, out total);
                    if (!flag)
                    {
                        Console.WriteLine("金额必须为整数或小数,请重新输入:");
                    }
                } while (!flag);
                Console.WriteLine("请输入你要发起的红包个数:");
                do
                {
                    temp = Console.ReadLine();
                    flag = int.TryParse(temp, out num);
                    if (!flag)
                    {
                        Console.WriteLine("红包个数必须为整数,请重新输入:");
                    }
                } while (!flag);
            }

            total -= min * num;
            if (total < 0)
            {
                Console.WriteLine("抱歉,你的金额不足!");
                return;
            }

            //产生正态分布的随机红包金额,并计算相关的金额和数量保证数据的准确性
            double average = total / num;
            double variance = 1;
            Random u1 = new Random();
            Random u2 = new Random();
            double[] nums = new double[num];

            for (int i = 0; i < num; i++)
            {
                double? result = total;
                if (i < num - 1 &&
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

smartsmile2012

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值