欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來(lái)到入門(mén)教程網(wǎng)!

C#教程

當(dāng)前位置:主頁(yè) > 軟件編程 > C#教程 >

C#生成隨機(jī)數(shù)功能示例

來(lái)源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C#教程|點(diǎn)擊: 次

本文實(shí)例講述了C#生成隨機(jī)數(shù)功能。分享給大家供大家參考,具體如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace csharp
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("生成隨機(jī)數(shù)\n");
      int randCount = 9;//隨機(jī)數(shù)發(fā)的個(gè)數(shù)
      int randMin = 1;//隨機(jī)數(shù)最小值
      int randMax = 21;//隨機(jī)數(shù)最大值
      int randIndex, flag, temp;
      randIndex = temp = flag = 0;
      Random rand = new Random();
      int[] randArr = new int[randCount];
      randArr[0] = rand.Next(randMin, randMax);
      while (true)
      {
        flag = 0;
        temp = rand.Next(randMin, randMax);
        for (int i = 0; i <= randIndex; i++)
        {
          if (temp == randArr[i])
          {
            flag = 1;
            break;
          }
        }
        if (flag == 1)//如果 flag == 1 則有重復(fù)的數(shù)字生成。
        {
          continue;
        }
        else if (flag == 0)
        {
          randIndex++;
          randArr[randIndex] = temp;
        }
        if (randIndex >= randCount - 1)//如果達(dá)到 randCount 退出循環(huán)
        {
          break;
        }
      }
      for (int i = 0; i < randCount; i++)
      {
        Console.WriteLine("arr[" + i + "]=" + randArr[i]);
      }
      Console.WriteLine("\n任意鍵退出。");
      Console.ReadLine();
    }
  }
}

生成無(wú)重復(fù)的隨機(jī)數(shù)

運(yùn)行結(jié)果如下:

更多關(guān)于C#相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《C#窗體操作技巧匯總》、《C#常見(jiàn)控件用法教程》、《WinForm控件用法總結(jié)》、《C#程序設(shè)計(jì)之線程使用技巧總結(jié)》、《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》、《C#數(shù)組操作技巧總結(jié)》及《C#面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》

希望本文所述對(duì)大家C#程序設(shè)計(jì)有所幫助。

上一篇:深入理解C# DateTime日期格式化

欄    目:C#教程

下一篇:c#中的泛型委托詳解

本文標(biāo)題:C#生成隨機(jī)數(shù)功能示例

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/6024.html

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有