flask-如何設定配置?
阿新 • • 發佈:2020-12-26
問題描述:
假定已經獲取題庫中的試題號,並存放在陣列arrayKT中。例如, int [] arrayKT={10,13,18,19,20,22,30,31…}。定義一個靜態成員方法,該方法實現從上述陣列中隨機抽出給定數量(n,1<=n<=arrayKT.Length)的考題,並組成一個考題字串。比如,隨機從arrayKT中抽取5題組成考題字串:“10,18,20,22,30”。要求,組成考題字串中考題不重複,且一定在陣列中存在。自行設計程式驗證上述方法正確性。
程式碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace fengyun
{
class Program
{
static void Main(string[] args)
{
int [] arrayKT={10,13,18,19,20,22,30,31};
getKTH(5, arrayKT);
Console. ReadKey();
}
public static string getKTH(int n,params int [] arrayKT)
{
//提示:主體中使用random類
Random rd = new Random();
Console.Write("從題庫中抽出的題為:");
for (int j = 0; j < n; j++)
{
int index = rd.Next(0, arrayKT.Length);
Thread.Sleep(1000); //延時的辦法的方法來避免Random快速連續產生相同隨機數
Console.Write(" {0}",arrayKT[index]);
}
return "";
}
}
}
結果如下:
這裡寫圖片描述
並不能產生完全不同的隨機數,程式碼仍需要改進!