将随机字符创建到数组或列表中 [英] creating random char into an array or list
问题描述
嗨.
如何从字母表中选择12个字母(随机+随机顺序)并将其放入列表或数组中?不仅如此,我希望能够在列表中添加单词.
How do I choose 12 letters from the alphabet (randomly + random order) and place them into a list or an array? But not just that, I want to be able to add words to the list.
例如如果我想添加单词bridge,它将占用6个空格,从而为随机字母剩余6个位置.例如. DTRLGBYESI
E.g. if I want to add the word bridge, that will take up 6 spaces making 6 remaining places for random letters. E.G. DTRLGBYESI
致谢.
李
推荐答案
MyList.Add(word_characters);
MyList.Add(word_characters);
int count = 12-MyList.Count();
int count = 12-MyList.Count();
随机R =新的random();
random R = new random();
for(int i = 0; i< count; i ++)
for(int i=0;i<count;i++)
{
MyList.Add(Convert.toChar(R.next(65,91)));
MyList.Add(Convert.toChar(R.next(65, 91)));
}
如果要使用小写字母,请将65替换为97,将91替换为123
In case you want lower case letters, replace 65 with 97 and 91 with 123
然后用它放松一下
http://stackoverflow.com/questions/273313/randomize-a-listt-in-c-sharp
http://stackoverflow.com/questions/273313/randomize-a-listt-in-c-sharp
这篇关于将随机字符创建到数组或列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!