for迴圈得到的隨機數相同

zhaohjjq發表於2013-12-25
 public partial class jshtml : System.Web.UI.Page
    {
        public   string qq = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack){

                for (int i = 0; i < 20; i++)
                {

                    Thread.Sleep(1);
                    long tick = DateTime.Now.Ticks;//一個以0.1納秒為單位的時間戳,18位
                    int seed = int.Parse(tick.ToString().Substring(9)); //  int型別的最大值:  2147483647//或者使用unchecked((int)tick)也可
                    Random ran = new Random(seed);
                    int iResult;
                    int iUp =30;
                    int iDown = 16;
                    iResult = ran.Next(iDown, iUp);
                    Response.Write(iResult + "<p>");
                }
              
            }

        }
    }

相關文章