1. 程式人生 > >C#獲取隨機數,真正的隨機數

C#獲取隨機數,真正的隨機數

//親測無問題

      byte[] buffer = Guid.NewGuid().ToByteArray();
        int iSeed = BitConverter.ToInt32(buffer, 0);
        Random random = new Random(iSeed);
        //Random random = new Random(new Guid().GetHashCode());//也有人用這種寫法,這種寫法是有問題的,不信請測試
        for (int i = 0; i < 100; i++)
        {
            Response.Write(random.Next(
0, 100) + "<br>"); }