Generate random samples from a user-defined distribution

Author: Lukas Breitwieser
In this tutorial we demonstrate how to create a random number generator that draws samples from a user-defined distribution.

Let's start by setting up BioDynaMo notebooks

We have to create a TCanvas object to draw results in this notebook.

Let's assume that we want to generate random numbers from a student-t distribution.
Class Random does not provide a direct function for that.
Therefore, we use the user-defined distribution feature Random::GetUserDefinedDistRng1D.
Fortunately, ROOT already provides a function called tdistribution_pdf that we can use.
Have a look at the following two links for more math functions: TMath and statistical functions

The returned random number generator has a function to draw the distribution.

In the next step we want to verify that the created random number generator follows the specified distribution.
Therefore, we create a histogram with 100 bins in the range [-5, 10] and fill it with 10000 samples.

Let's draw the result:

As we can see from the last figure the samples from our random number generator fit our distribution.