BorrowedTorch.Randomness 1.2.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package BorrowedTorch.Randomness --version 1.2.0
                    
NuGet\Install-Package BorrowedTorch.Randomness -Version 1.2.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="BorrowedTorch.Randomness" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BorrowedTorch.Randomness" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="BorrowedTorch.Randomness" />
                    
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 BorrowedTorch.Randomness --version 1.2.0
                    
#r "nuget: BorrowedTorch.Randomness, 1.2.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 BorrowedTorch.Randomness@1.2.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=BorrowedTorch.Randomness&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=BorrowedTorch.Randomness&version=1.2.0
                    
Install as a Cake Tool

BorrowedTorch.Randomness

Seeded random streams and noise for procedural generation. The same seed gives the same numbers on every platform, every .NET version and every version of this package, so a world seed always rebuilds the same world.

using BorrowedTorch.Randomness;

var world = new Rng(worldSeed);

var mazeRng = world.Fork("maze", floor);   // one stream per system (and per floor)
var lootRng = world.Fork("loot");          // draws here never shift the maze

int roll = lootRng.NextInt(1, 7);          // unbiased (Lemire's method)
bool trap = mazeRng.NextBool(0.1);

var chunk = StableHash.Of("chunk");        // in hot loops, hash the key once:
var chunkRng = world.Fork(chunk, index);   // same stream as world.Fork("chunk", index)

// Noise: pure functions of (seed, x, y), no period, so an infinite world can be sampled in any order.
var caves = new FractalNoise(world.Fork("caves").Seed, FractalSettings.Default with { Octaves = 5 });
bool open = caves.Sample(cellX, cellY) > 0.05;

What is in it

Type Purpose
Rng PCG32 generator: NextUInt, NextInt, NextDouble, NextBool, Pick, Shuffle, Fork
StableHash FNV-1a 64 + SplitMix64: stable seeds from strings, Combine, Mix
GradientNoise 2D Perlin-style gradient noise in [-1, 1] on a hashed lattice: stateless, no period
FractalNoise fBm: octaves of GradientNoise with their own seeds and offsets, normalized to [-1, 1]
FractalSettings Frequency, octaves, lacunarity, gain as a plain record (Default with { ... })

Guarantees

  • Output is frozen. No release will change what an existing method returns for a given seed, including how Fork derives seeds. A new algorithm ships as a new type. The golden-value tests (KnownValues_*) enforce this for every method, on .NET 8 and 10.
  • Noise is bit-identical everywhere. It uses only IEEE add, subtract, multiply and floor (no Math.Sin, Math.Pow or permutation tables), and its golden values are tested on .NET 8 and 10 like Rng's.
  • Forks depend only on the parent's seed and the key, not on how many numbers the parent has drawn, so systems stay independent of each other's call order.
  • Fork keys are part of your save format. Renaming "maze" changes every maze for every saved seed.

Not for security

Rng is predictable by design. Never use it for anything adversarial (anti-cheat, multiplayer authority, tokens, keys); use System.Security.Cryptography.RandomNumberGenerator instead.

Build

dotnet test
dotnet pack src/BorrowedTorch.Randomness -c Release -o artifacts
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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.
  • net8.0

    • No dependencies.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on BorrowedTorch.Randomness:

Package Downloads
BorrowedTorch.Nature

Nature for MonoGame (compute fork), generated and drawn on the GPU: grass, a procedural sky seen through air worked out from wherever the viewer is, from the ground to orbit, with volumetric clouds, and the wind for anything to move in.

BorrowedTorch.FabricSimulator

GPU cloth solver for MonoGame: a compute shader integrates the particles, relaxes the constraints and computes the normals, and the positions never leave the GPU. Verlet integration with Jacobi relaxation, plastic bending so creases stay, long-range attachments, colliders with friction, self-collision through a spatial hash, cuts, rips and tearing under strain, and drag against wind you set every frame. Solver only - you fetch the particles in your own vertex shader and draw the sheet yourself. Requires Windows and the compute-capable MonoGame fork. The solver ships as HLSL and is compiled by your content pipeline.

BorrowedTorch.Engine

Kindling, Borrowed Torch's game engine: what a game's own code builds against - its features registering components, systems, keys and UI handlers - for the Kindling editor and player to run

BorrowedTorch.Architecture

Procedural level architecture for grid- and tile-based games: cell-space footprint masks, grid layouts whose edges are walls, openings or doors, a seeded perfect-maze generator (recursive backtracker) with distance and dead-end queries, and tilers that turn a layout into a thick-wall or thin-wall tile map.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.4.0 376 11/2/2026
1.3.0 205 11/2/2026
1.2.0 121 10/20/2026
1.1.0 142 10/20/2026