Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Engine Works

Under the hood of Alteryx: tips, tricks and how-tos.
ned_blog
8 - Asteroid

I got asked the question of how to generate random numbers with a normal distribution. A quick search online provides all kinds of formulas, it is a simple matter of picking one to implement. I could of course implement this in the formula library in C++, but that doesn't provide instant gratification, so off writing a macro I go. Some of the functions are iterative, which would be slower and more difficult in Alteryx, so I chose a simpler formula. The formulas online also produce a normal distribution with and average of 0 and a standard deviation of 1. Depending on the data you are trying to model, you probably want to change that. Rather than make the use do it, I added some parameters in the macro.

 

Finally, anytime you write a macro it is nice to test it. I wrote a quick module to generate 1,000,000 random #'s and test their average, StdDev, and also produce a chart so you can visually confirm that it is a norm distribution.

 

The results of that are:

Number of Iterations Tested: 1,000,000

Average(should be close to 100): 100.02

Standard Deviation (should be close to 15): 14.98

 

 

My favorite part of this is I used the chart that the test module produced as the icon for the macro. Kind of recursive. Anyway, now generating random numbers with a Gaussian Distribution is as easy as dragging out a macro. The macro and test module can be found here.

 

Comments