如何在C#中将随机字符串数组添加到字符串?

时间:2015-01-21 01:38:17

标签: c# arrays random

我有一个需要过滤用户输入游戏1到4个游戏的表单,然后用户需要输入动物编号到启用的固定动物文本框。

再次,用户还需要在随机按钮之前输入文本框中的游戏数量。

总游戏(随机输出)是5动物示例:23-22-12-34-40 点击随机按钮后,它将固定前3个动物编号,然后将剩下的2个动物编号随机放在3个固定动物旁边,直到游戏等于整个游戏。空白示例:

enter image description here

下图是示例输入过滤器: enter image description here

根据示例图像,总游戏数为3,然后我希望输出随机显示在列表框中,如下所示:

  

23-22-12-34-40

     

23-22-12-14-34

     

23-22-12-11-17

我试图只过滤一个游戏,但我仍然没有运气:

TextBox[] GameTwoFixed = new TextBox[4] { txtFixedAnimalSales1, txtFixedAnimalSales2, txtFixedAnimalSales3, txtFixedAnimalSales4 };
        string[] NumberPlay1 = new string[5];
        string play = txtFixedTypeTwo.Text;
        string Game = "";
        string CountGame = txtCountGameTwo.Text;
        if(play != "")
        {
            if (CountGame != "")
            {
                if (play == "1")
                {
                    string GetRandom = RandomGenerator();
                    List<string> setGame = new List<string>();
                    do
                    {
                        if (!setGame.Contains(GetRandom))
                        {
                            setGame.Add(GetRandom);
                        }
                    }
                    while (setGame.Count == Convert.ToInt32(CountGame));
                }
            }
        }

那么无论如何要处理这个问题? 以下是我上述问题的随机函数:

public Random RandomGeneration = new Random();    
public string RandomGenerator()
    {
        string[] arr = {"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40"};
        int number = RandomGeneration.Next(0, arr.Length);
        return arr[number].ToString();
    }

提前致谢

0 个答案:

没有答案