Search⌘ K

Empty Distribution

Explore the implementation of the Empty Distribution in C# as a key component in discrete probability models. This lesson helps you understand how to manage cases where distributions have no support, ensuring safer and more robust code when working with System.Random improvements.

Previously, we mentioned that we will be needing the empty distribution.

Implementing the Empty Distribution

In this lesson, we will be implementing the Empty Distribution.

public sealed class Empty<T> : IDiscreteDistribution<T>
{
  public static readonly Empty<T> Distribution = new Empty<T>();
  private Empty() { }
  public T Sample() => throw new Exception(“Cannot sample from empty distribution”);
  public IEnumerable<T> Support() => Enumerable.Empty<T>();
  public int Weight(T t) => 0;
}

Now that we have this, we can fix up our other distributions to use it. The ...