Day 4 ~ Custom Distribution : Controlling the Random

in coding •  7 years ago  (edited)

Day 4

This my fourth post on the 100 days of learning challenge I set myself.You can read more about this years goals here.

Last time I looked at how Normal Distrobution can make make random numbers consistently closer to the mean.

Let's customize the distribution a little.

Back to cacti, say we wanted to model a mature group of cacti that are all very tall.

cactus.jpg

We might create a function like this:

code.png

We would just push the first number if we wanted to model younger smaller cacti.

Here is a quick chart showing accumulated total of the two generated data sets:

chart.png

You can view the code behind the chart in the link below:

See the Pen Custom Distribution by Adam Harpur (@harps116) on CodePen.

As you can see the tall biased set contains significantly larger numbers than the smaller biased set.

Happy Coding!

Check out Daniel Shiffman's great series on the Nature of Code, this 100 days of learning is a great excuse for me to finally work through the lessons and take some notes as I go.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!