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
                    
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="Fireball.Fireworks.Rng" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fireball.Fireworks.Rng" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Fireball.Fireworks.Rng" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Fireball.Fireworks.Rng --version 1.0.0
                    
#r "nuget: Fireball.Fireworks.Rng, 1.0.0"
                    
#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.
#:package Fireball.Fireworks.Rng@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Fireball.Fireworks.Rng&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Fireball.Fireworks.Rng&version=1.0.0
                    
Install as a Cake Tool

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 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. 
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.0.0 76 7/26/2026