-
Notifications
You must be signed in to change notification settings - Fork 0
/
RandOrgInterface.cs
48 lines (42 loc) · 1.43 KB
/
RandOrgInterface.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.IO;
using HtmlAgilityPack;
using System.Net;
namespace BoardGameChooser
{
public static class RandOrgInterface
{
static HtmlWeb web = new HtmlWeb();
public static int RandInt(int min, int max)
{
try
{
string url = @"https://www.random.org/integers/?num=1&min=" + min.ToString() + @"&max=" + (max - 1).ToString() + @"&col=1&base=10&format=plain&rnd=new";
string result = string.Empty;
HttpWebRequest req = WebRequest.CreateHttp(url);
req.Timeout = 3000;
req.Accept = "text/html";
req.UserAgent = @"Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36";
WebResponse res = req.GetResponse();
StreamReader reader = new StreamReader(res.GetResponseStream());
result = reader.ReadToEnd();
reader.Close();
res.Close();
return int.Parse(result.Trim());
}
catch
{
return Form1.settings.rand.Next(min, max);
}
}
}
}