Continued integration and testing of true randomness.
This commit is contained in:
43
osrs-toolbox/APIs/Random/Random.cs
Normal file
43
osrs-toolbox/APIs/Random/Random.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public static class Random
|
||||
{
|
||||
private static string BaseEndpoint = @"https://api.random.org/json-rpc/4/invoke";
|
||||
private static string APIKey = APIKeys.RANDOM;
|
||||
|
||||
public static async Task<int[]> GetRandomIntegersAsync(int Minimum, int Maximum, int Count, bool AllowDuplicates)
|
||||
{
|
||||
RandomIntegerRequest Request = new RandomIntegerRequest()
|
||||
{
|
||||
parameters = new()
|
||||
{
|
||||
apiKey = APIKey,
|
||||
n = Count,
|
||||
min = Minimum,
|
||||
max = Maximum,
|
||||
replacement = AllowDuplicates
|
||||
}
|
||||
};
|
||||
string TestString = string.Empty;
|
||||
TestString += string.Format("{0}: {1}\n", nameof(Request.jsonrpc), Request.jsonrpc);
|
||||
TestString += string.Format("{0}: {1}\n", nameof(Request.method), Request.method);
|
||||
string RequestJson = Request.GetJson();
|
||||
TestString += string.Format("{0}\n", RequestJson);
|
||||
string ResponseJson = await RestServices.GetPostResponseAsync(new Uri(BaseEndpoint), RequestJson, APIKey).ConfigureAwait(false);
|
||||
TestString += string.Format("{0}", ResponseJson);
|
||||
MessageBox.Show(TestString);
|
||||
RandomIntegerRequestResponse response = JsonSerializer.Deserialize<RandomIntegerRequestResponse>(ResponseJson);
|
||||
return response.result.random.data;
|
||||
//return TestString;
|
||||
//return ResponseJson;
|
||||
}
|
||||
}
|
||||
}
|
56
osrs-toolbox/APIs/Random/RandomIntegerRequest.cs
Normal file
56
osrs-toolbox/APIs/Random/RandomIntegerRequest.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlTypes;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public class RandomIntegerRequest
|
||||
{
|
||||
public string jsonrpc { get; set; } = "2.0";
|
||||
public string method { get; set; } = "generateIntegers";
|
||||
[JsonPropertyName("params")]
|
||||
public RandomIntegerRequestParameters parameters { get; set; } = new();
|
||||
public long id { get; set; } = DateTime.Now.Ticks;
|
||||
|
||||
public string GetJson()
|
||||
{
|
||||
return JsonSerializer.Serialize<RandomIntegerRequest>(this);
|
||||
}
|
||||
}
|
||||
|
||||
public class RandomIntegerRequestParameters
|
||||
{
|
||||
public string apiKey { get; set; }
|
||||
public int n { get; set; }
|
||||
public int min { get; set; }
|
||||
public int max { get; set; }
|
||||
public bool replacement { get; set; }
|
||||
}
|
||||
|
||||
public class RandomIntegerRequestResponse
|
||||
{
|
||||
public string jsonrpc;
|
||||
public RandomIntegerResult result;
|
||||
public int id;
|
||||
}
|
||||
|
||||
public class RandomIntegerResult
|
||||
{
|
||||
public RandomIntegerData random;
|
||||
public int bitsUsed;
|
||||
public int bitsLeft;
|
||||
public int requestsLeft;
|
||||
public int advisoryDelay;
|
||||
}
|
||||
|
||||
public class RandomIntegerData
|
||||
{
|
||||
public int[] data;
|
||||
public DateTime completionTime;
|
||||
}
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public static class Random
|
||||
{
|
||||
private static string BaseEndpoint = @"https://api.randdom.org/json-rpc/4/invoke";
|
||||
private static string APIKey = APIKeys.RANDOM;
|
||||
}
|
||||
}
|
@@ -16,7 +16,13 @@ namespace osrs_toolbox
|
||||
|
||||
private async void DoTest(object obj)
|
||||
{
|
||||
TestOutput = await Wiki.TestAsync();
|
||||
int[] test = await Random.GetRandomIntegersAsync(0, 36, 8, false);
|
||||
string TestString = string.Empty;
|
||||
foreach(int i in test)
|
||||
{
|
||||
TestString += string.Format("{0}\n", i);
|
||||
}
|
||||
TestOutput = TestString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -85,8 +85,4 @@
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="APIs\Random\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Reference in New Issue
Block a user