.Net基礎篇_學習筆記_第七天_隨機數的產生

來源:互聯網
上載者:User

標籤:and   eric   不能   str   main   names   .net   int   ati   

 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6  7 namespace 第六天_流程語句 8 { 9     class Program10     {11         static void Main(string[] args)12         {13             Random r = new Random();                                                         //1.建立一個能產生隨機數的對象14             while (true)15             {16                 int _numR = r.Next(1, 10);                                                         //2.讓產生隨機數的這個對象 調用方法來產生隨機數             能取到1到不能取到10,左閉右開區間。17                 Console.WriteLine(_numR);18                 Console.ReadKey();19             }    20         }21     }22 }
 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6  7 namespace 第六天_流程語句 8 { 9     class Program10     {11         static void Main(string[] args)12         {13             Random r = new Random();                                                              //1.建立一個能產生隨機數的對象      14             while (true)15             {16                 int _numR = r.Next(1, 7);                                                         //2.讓產生隨機數的這個對象 調用方法來產生隨機數             能取到1到不能取到7,左閉右開區間。6種可能17                 Console.WriteLine("請輸入您的名字:");18                 string _name = Console.ReadLine();                                                //虛擬碼,對下面操作無影響  19                 switch (_numR)20                 {21                     case 1:22                         Console.WriteLine("你上輩子是個大臣");23                         break;24                     case 2:25                         Console.WriteLine("你上輩子是個諸侯");26                         break;27                     case 3:28                         Console.WriteLine("你上輩子是個農民");29                         break;30                     case 4:31                         Console.WriteLine("你上輩子是個王子");32                         break;33                     case 5:34                         Console.WriteLine("你上輩子是個公主");35                         break;36                     default:37                         Console.WriteLine("你上輩子是個侍女");38                         break;39 40                 }41              Console.ReadKey();42             }      43         }44     }45 }

 

.Net基礎篇_學習筆記_第七天_隨機數的產生

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.