# Power Law distribution for a given exponent in C# using MathNet

I am currently working on a project where I need to generate multiple values (floats or doubles preferably) that follow a power law distribution with a given exponent!

I was advised to use the MathNet.Iridium library to help me. The problem I have is that the documentation is not as explicit as it should be if there is any!

I see multiple distributions that fit the general idea of the power law distribution but I cannot pinpoint a good distribution to use with a certain exponent as a parameter.

Does anybody have more experience in that matter and could give me some hints or advice?

## Answers

To generate values of a distribution of your choice, you could use the inverse cumulative distribution function, as mentioned in the wikipedia.

Step by step, this would look like:

- Choose a distribution function that you like.
- Calculate the inverse cumulative distribution function using pen and paper.
- Generate a value based on a uniform distribution on the unit interval. Random will do nicely here.
- Input the value into your ICDF.

The result is a value chosen at random using your chosen distribution function.

If you run into problems with step 2, maybe the folks at https://mathoverflow.net/ can help you.

**Edit:** If you just need any power law distribution with exponent gamma, this will generate one value:

double r = 1.0 / Math.Pow(1-new Random().NextDouble(), 1.0/(gamma+1));