Generate random values in C#

后端 未结 9 1910
执笔经年
执笔经年 2020-12-01 06:15

How can I generate random Int64 and UInt64 values using the Random class in C#?

9条回答
  •  甜味超标
    2020-12-01 06:52

    I always use this to get my random seed (error checking removed for brevity):

    m_randomURL = "https://www.random.org/cgi-bin/randnum?num=1&min=1&max=1000000000";
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(m_randomURL);
    StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
    Random rand = new Random(Convert.ToInt32(stIn.ReadToEnd()));
    

    random.org uses atmospheric noise to generate the randomness and is apparently used for lotteries and such.

提交回复
热议问题