RandomOrg.CoreApi 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package RandomOrg.CoreApi --version 1.0.1                
NuGet\Install-Package RandomOrg.CoreApi -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RandomOrg.CoreApi" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RandomOrg.CoreApi --version 1.0.1                
#r "nuget: RandomOrg.CoreApi, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install RandomOrg.CoreApi as a Cake Addin
#addin nuget:?package=RandomOrg.CoreApi&version=1.0.1

// Install RandomOrg.CoreApi as a Cake Tool
#tool nuget:?package=RandomOrg.CoreApi&version=1.0.1                

This is the official .NET implementation of the RANDOM.ORG JSON-RPC API (Release 4), which supports .NET Standard 2.0+, .NET Core 2.0+, .NET 5 and .NET Framework 4.6.1+.

It provides either serialized or unserialized access to both the signed and unsigned methods of the API through the RandomOrgClient class. It also provides a convenience class through the RandomOrgClient class, the RandomOrgCache, for precaching requests. In the context of this module, a serialized client is one for which the sequence of requests matches the sequence of responses.

Dependencies

The library requires the Newtonsoft.Json package for normal operation.

Usage

This library is comprised of the RandomOrg.CoreApi and RandomOrg.CoreApi.Errors namespaces.

using RandomOrg.CoreApi;
using RandomOrg.CoreApi.Errors;
  • RandomOrg.CoreApi contains the RandomOrgClient and RandomOrgCache classes
  • RandomOrg.CoreApi.Errors contains the following custom error classes:
    • RandomOrgBadHTTPResponseException
    • RandomOrgInsufficientBitsException
    • RandomOrgInsufficientRequestsException
    • RandomOrgJSONRPCException
    • RandomOrgKeyNotRunningException
    • RandomOrgRANDOMORGException
    • RandomOrgSendTimeoutException
    • RandomOrgCacheEmptyException

The default setup is best for non-time-critical serialized requests, e.g., batch clients:

RandomOrgClient roc = RandomOrgClient.GetRandomOrgClient(YOUR_API_KEY_HERE);
try {
	int[] response = roc.GenerateIntegers(5, 0, 10);
	Console.WriteLine(string.Join(",", response));
} catch (...) { ... }

Example output: 9, 5, 4, 1, 10

...or for more time sensitive serialized applications, e.g., real-time draws, use:

RandomOrgClient roc = RandomOrgClient.GetRandomOrgClient(YOUR_API_KEY_HERE, 2000, 10000, true);
try {
	Dictionary<string, object> response = roc.GenerateSignedIntegers(5, 0, 10);
	Console.WriteLine(string.Join(Environment.NewLine, response));
} catch (...) { ... }

[data, System.Int32[]]
[random, {
    "method": "generateSignedIntegers",
    "hashedApiKey": "HASHED_KEY_HERE",
    "n": 5,
    "min": 0,
    "max": 10,
    "replacement": true,
    "base": 10,
    "data": [
      3,
      9,
      8,
      8,
      0
    ],
    "license": {
      "type": "developer",
      "text": "Random values licensed strictly for development and testing only",
      "infoUrl": null
    },
    "userData": null,
    "ticketData": null,
    "completionTime": "2021-02-16 19:01:38Z",
    "serialNumber": 5623
}]
[signature, SIGNATURE_HERE]

If obtaining some kind of response instantly is important, a cache should be used. A cache will populate itself as quickly and efficiently as possible allowing pre-obtained randomness to be supplied instantly. If randomness is not available - e.g., the cache is empty - the cache will throw a RandomOrgCacheEmptyException allowing the lack of randomness to be handled without delay:

RandomOrgClient roc = RandomOrgClient.GetRandomOrgClient(YOUR_API_KEY_HERE);
RandomOrgCache<int[]> c = roc.CreateIntegerCache(5, 0, 10);
while (true) {
	try {
		int[] randoms = c.Get();
		Console.WriteLine(string.Join(",", randoms));
	} catch (RandomOrgCacheEmptyException) {
		// handle lack of true random number here
		// possibly use a pseudo random number generator
	}
}

10, 3, 1, 9, 0
8, 9, 8, 3, 5
3, 5, 2, 8, 2
...

Note that caches don't support signed responses as it is assumed that clients using the signing features want full control over the serial numbering of responses.

Finally, it is possible to request live results as-soon-as-possible and without serialization, however this may be more prone to timeout failures as the client must obey the server's advisory delay times if the server is overloaded:

RandomOrgClient roc = RandomOrgClient.GetRandomOrgClient(YOUR_API_KEY_HERE, 0, 10000, false);
try {
	int[] randoms = roc.GenerateIntegers(5, 0, 10);
	Console.WriteLine(string.Join(",", randoms));
} catch (...) { ... }

[8, 10, 10, 4, 0]

Signature Verification

There are two additional methods to generate signature verification URLs and HTML forms (CreateUrl and CreateHtml) using the random object and signature returned from any of the signed (value generating) methods. The generated URLs and HTML forms link to the same web page that is also shown when a result is verified using the online Signature Verification Form.

Documentation

For a full list of available randomness generation functions and other features see the library documentation and https://api.random.org/json-rpc/4

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 3,768 4/12/2023
1.0.1 461 12/17/2021
1.0.0 352 8/10/2021

This is a minor update to the documentation of this library. For more information please check the corresponding Github repository (https://github.com/RandomOrg/JSON-RPC-.NET) or the RANDOM.ORG JSON-RPC Core API documentation (https://api.random.org/json-rpc/4).