用C#实现简单的抽奖

嗯,很简单的代码,仅仅实现了概率增加的功能,所以大佬勿喷,上代码:

using System;
using  static System.Console;
class A
{
    public static void Main(string[] vs)
    {
        WriteLine("请输入A或a抽奖");
        int b = 0;//判断次数的字段
        do
        {
            string z = ReadLine();
            if (z == "a")
            {
                var a = new Random();
                int i = a.Next(1, 50);
                if (b >= 5)//增加概率
                {
                    i = a.Next(1, 30);
                }
                if (b >= 10)//增加概率
                {
                    i = a.Next(1, 20);
                }
                if (i == 3)
                {
                    WriteLine("nice");
                    ReadLine();
                    break;
                }
                if (i != 3)
                {
                    b++;
                    WriteLine("Not Found 404");
                    WriteLine(b);
                }
            }
        } while (true);
    }
}

PS:除非是一小段或不长的代码否则给变量随便起个变量名是很傻的行为,不要学我......要在变量名前用带有前缀字母来表示某个数据类型,例如:isright表示一个布尔值(bool),不过最好反映出变量的实例功能

没用的小知识1:

在C#6.0中更新了一个叫内插字符串的特性:

      static void Main(string[] args)
      {
         int a=3;
         Console.WriteLine($"lt is {a}");
         Console.ReadKey();
      }

呵呵,神奇的知识

嗯,下期在见了:) 

posted on 2022-06-30 19:39  hopeitdoes  阅读(546)  评论(0)    收藏  举报