PinkUrnModel 1.1.1

dotnet add package PinkUrnModel --version 1.1.1
                    
NuGet\Install-Package PinkUrnModel -Version 1.1.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="PinkUrnModel" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PinkUrnModel" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="PinkUrnModel" />
                    
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 PinkUrnModel --version 1.1.1
                    
#r "nuget: PinkUrnModel, 1.1.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.
#:package PinkUrnModel@1.1.1
                    
#: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=PinkUrnModel&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=PinkUrnModel&version=1.1.1
                    
Install as a Cake Tool

Pink Urn

The Pink Urn is a specialized probability urn model that improves the consistency of random event distributions, such as those found in MMO games. It transforms a simple constant probability event model into a negative hypergeometric distribution, which helps smooth out streaks of successes and failures, creating a more balanced player experience.

How It Works

In the Pink Urn model:

  • The urn contains a mix of red (event) balls and white (non-event) balls.
  • When a white ball is drawn, it is not replaced, increasing the chances of drawing a red ball on subsequent trials.
  • When a red ball is drawn, the urn resets, and the process begins again.

This simulates a system where, while events are still random, players are less likely to experience long streaks of failures (or successes), providing a more consistent experience. The Pink Urn model approximates the mean success rate of a constant probability event but with a smaller variance.

Features

  • Configurable Probability: Specify a desired success probability, and the urn model will approximate it using a discrete negative hypergeometric distribution.
  • Reduced Variance: The Pink Urn reduces the variability of streaks in random outcomes. Success and failure streaks are shorter on average than in a standard random model.
  • Deterministic Results: The system operates deterministically once initialized with its parameters.
  • Resets After Event: When a successful event occurs, the urn resets to its initial state, ensuring fairness over multiple trials.

Usage

The Pink Urn class can be used to model events with more consistent probabilities in games or simulations.

Example

using PinkUrnModel;

class Program
{
    static void Main()
    {
        // Create a Pink Urn with an average 0.02 probability of success
        PinkUrn urn = new PinkUrn(0.02);

        // Simulate 10 trials
        Random random = new Random();
        for (int i = 0; i < 10; i++)
        {
            bool result = urn.GetResult(random.NextDouble());
            Console.WriteLine(result ? "Success" : "Failure");
        }
    }
}

API

  • PinkUrn(int redBalls, int whiteBalls)
    Initializes the Pink Urn with a specific number of red (event) and white (non-event) balls.

    PinkUrn urn = new PinkUrn(5, 100);
    
  • PinkUrn(double probability, int scalar = 3)
    Initializes the Pink Urn with a given probability, automatically calculating the red and white ball counts.

    PinkUrn urn = new PinkUrn(0.02);
    
  • bool GetResult(int index)
    Returns whether or not the event occurs at the given index. The result is deterministic based on the current state of the urn.

    bool success = urn.GetResult(randomIndex);
    
  • bool GetResult(double time)
    Returns the event result based on a time value in the unit interval [0, 1], where the urn’s total number of balls is indexed.

    bool success = urn.GetResult(0.75);
    
  • void Reset()
    Resets the urn to its initial state.

    urn.Reset();
    

Simulation Results

We simulated the Pink Urn model and a simple constant probability model over 50,000 players performing 40,000 trials each using a 0.02 probability of success. Here are the results:

Model Successes Failures Mean Probability Mean Failure Streak Failure Streak Std. Dev. Best Failure Streak
Simple 39,992,769 1,960,007,231 0.0199963845 49.00904038 49.44142142 988
Pink Urn 39,986,123 1,960,013,877 0.0199930615 49.01735227 34.99427645 147

The Pink Urn model has a lower standard deviation of successes, failures, and failure streaks, meaning that it creates a more consistent experience across players. Players in the Pink Urn model also experience shorter extreme failure streaks, reducing frustration caused by long runs of bad luck.

Installation

To install the Pink Urn library via NuGet:

dotnet add package PinkUrn --version 1.0.0

Or search for PinkUrn in your NuGet package manager.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

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.1 215 9/16/2024
1.1.0 167 9/16/2024
1.0.0 171 9/16/2024