Fireball.Fireworks.Rng
1.0.0
dotnet add package Fireball.Fireworks.Rng --version 1.0.0
NuGet\Install-Package Fireball.Fireworks.Rng -Version 1.0.0
<PackageReference Include="Fireball.Fireworks.Rng" Version="1.0.0" />
<PackageVersion Include="Fireball.Fireworks.Rng" Version="1.0.0" />
<PackageReference Include="Fireball.Fireworks.Rng" />
paket add Fireball.Fireworks.Rng --version 1.0.0
#r "nuget: Fireball.Fireworks.Rng, 1.0.0"
#:package Fireball.Fireworks.Rng@1.0.0
#addin nuget:?package=Fireball.Fireworks.Rng&version=1.0.0
#tool nuget:?package=Fireball.Fireworks.Rng&version=1.0.0
Fireball RNG
A server-side C# client for the Fireball Random Number Generator (RNG) service. It is not a local pseudo-random number generator — every value returned by IRng originates from the remote RNG service, so game outcomes are centrally sourced and auditable. Values are prefetched into a local buffer so callers rarely wait on the network.
Table of Contents
Installation
dotnet add package Fireball.Fireworks.Rng
Or via the NuGet Package Manager in Visual Studio:
Install-Package Fireball.Fireworks.Rng
Configuration
FireballRng reads its configuration from environment variables at startup and throws ArgumentException immediately if either is missing or invalid.
| Variable | Required | Description |
|---|---|---|
RNG_URL |
Yes | Absolute URL of the RNG service endpoint. |
RNG_BUFFER_SIZE |
Yes | Number of values fetched per batch. Values are served from a local buffer that refills in the background once it falls below half. |
Quick Start
1. Register dependencies
In your Program.cs or Startup.cs, call AddFireworksRng() on your IServiceCollection:
using Fireball.Fireworks.Rng;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddFireworksRng();
This registers the named HTTP client, the retry and timeout policies via Polly, and IRng as a singleton.
2. Inject IRng
using Fireball.Fireworks.Rng;
public class MyGameFunction
{
private readonly IRng _rng;
public MyGameFunction(IRng rng)
{
_rng = rng;
}
public async Task DealCard()
{
var cardIndex = await _rng.NextInt(1, 53);
var prizeIndex = await _rng.IndexByWeights(new List<double> { 50, 30, 15, 5 });
var deck = Enumerable.Range(1, 52).ToList();
await _rng.Shuffle(deck);
}
}
API Reference
| Method | Returns | Description |
|---|---|---|
NextInt(int min, int max) |
Task<int> |
A 32-bit integer greater than or equal to min and less than max. |
NextInt(int max) |
Task<int> |
A 32-bit integer greater than or equal to 0 and less than max. |
NextDouble(double min, double max) |
Task<double> |
A double greater than or equal to min and less than max. |
NextBool() |
Task<bool> |
A randomly selected boolean value. |
IndexByWeights(List<double> weights) |
Task<int> |
The index of an element selected proportionally to the supplied weights. |
Shuffle<T>(IList<T> list) |
Task |
Shuffles the list in place using the Fisher–Yates algorithm. |
Every member throws RNGException if the RNG service cannot be reached, and ArgumentOutOfRangeException when given invalid bounds or weights.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Google.Apis.Auth (>= 1.75.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Http.Polly (>= 10.0.10)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.10)
- Newtonsoft.Json (>= 13.0.4)
- Polly (>= 8.7.0)
- Polly.Extensions.Http (>= 3.0.0)
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 | 76 | 7/26/2026 |