RandomOrg.CoreApi 1.0.0

Install-Package RandomOrg.CoreApi -Version 1.0.0
dotnet add package RandomOrg.CoreApi --version 1.0.0
<PackageReference Include="RandomOrg.CoreApi" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RandomOrg.CoreApi --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RandomOrg.CoreApi, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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.0

// Install RandomOrg.CoreApi as a Cake Tool
#tool nuget:?package=RandomOrg.CoreApi&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

This is a .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]

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

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.0.0 81 8/10/2021

This is the first release of the official .NET library for the RANDOM.ORG Core API (R4). 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).