随笔 - 8  文章 - 0  评论 - 0  阅读 - 2103

用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   hopeitdoes  阅读(513)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示