Python Random Library

The python random library is a very powerful tool for anyone interested in doing any kind of statistical analysis. It can be useful for use cases related to internet security as well, and gaming. Getting started with random is fairly easy since it’s a module that already comes packages with python. Consider this simple example where we print a random integer from 1 to 10:

import random


print(random.randint(1,10))

My Freelance Paycheck – Start Your Career as a Freelancer Today!

You can also get real-valued distributions easily with the random library. You might have to do a little research if you’re not familiar with these, but you can find them in any text on statistical mathematics. Consider the following example which demonstrates these:

import random

randomArray = []
uniformArray = []
gaussianArray = []

for i in range(1,100):
randomArray.append(random.random())
uniformArray.append(random.uniform(1,100))
gaussianArray.append(random.gauss(1,100))

print(randomArray)
print(uniformArray)
print(gaussianArray)

You will see three arrays printed to the console. One for each of the different distributions.

I hope this simple example gets you on your way to using python for statistical analysis. For a complete list of the methods you can use in the random library in python, please visit the official documentation for this module Here.

Start Making Money Trading BitCoin Today!

Leave a comment