Calculating a log normal value from an average and standard deviation

It's been a bit quiet round here recently due to project work at the office primarily with little Grasshopper work and little in the way of interesting snippets. However, one which I've decided to put here for future use is a function to calculate a log normal value from a given average and a given standard deviation from that average. I've used this function a few times now for one thing or another and keep having to refer to old code to find it when I need it again. That being inefficient, I decided to drop the function on here for later use, and maybe for someone else to find useful as well.

Function for calculating

The function takes two inputs, the average and the value representing one standard deviation from the average. If this values are more global in your code you can of course remove the parameters accordingly.

This is a pseudo-code implementation of generating a log normal value, mainly due to different languages having different implementations of generating random numbers.

C# seeding issue

Remember not to declare a new random instance in the for loop if you're doing this in C#, as you'll encounter difficulties from how the seeding works. If you intend to call this method often (e.g. within a for loop generating a load of log normal values) then I would strongly recommend putting the random instance as a global variable and calling it that way.

Leave a Reply

Your email address will not be published. Required fields are marked *