C#生成随机数的问题

来源:百度知道 编辑:UC知道 时间:2024/09/23 07:37:58
一个数组中有英文26个字母,我现在就是想随机抽出一个放在一个字符串中,执行20次,但是当我把Random rd = new Random();放到for循环里,如果直接按F5运行,只能显示同一个字母,如果我按F10一步一步调试,结果是正常的,请高手指点指点原因。
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(returnStr());
}
public string returnStr()
{
string str="";
string[] s = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
Random rd = new Random();
for (int i = 0; i < 20; i++)

{

str = str+"," + s[rd.Next(26)].ToString();
// str.Append(s[rd.Next(26)] +

public string returnStr()

        {

            Random rd = new Random();

            string str = "";

            string[] s = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };