RANDOM NUMBERS#

The RANDOM NUMBERS content is designed so that the participant can exploit the computer’s ability to perform various operations quickly.

This is an important paradigm shift that forces the participant to move from solving problems analytically to solving problems computationally. Therefore, avoid as much as possible to answer the proposed questions using combinatorial analysis.

The proposed problems are:

  • Rolling a Dice 🟢

  • Tossing Coins 🟡

  • Random Password 🟠

A very important concept related to random numbers is the probability distribution. So before moving on, at least take a look (below) at some distributions.

  • Take the opportunity to reflect on how important it is to choose the random function correctly.

Probability distribution#

import random
import seaborn as sns
sns.set_theme()

Uniform Distribution#

# INTEGER
distribution = [random.randint(1, 100) for _ in range(1000000)]
sns.histplot(data=distribution, bins=100)
<AxesSubplot:ylabel='Count'>
../../_images/intro_3_1.png
# REAL
distribution = [random.uniform(1, 100) for _ in range(1000000)]
sns.histplot(data=distribution)
<AxesSubplot:ylabel='Count'>
../../_images/intro_4_1.png
# SEQUENCE
distribution = random.choices(['A','B', 'C', 'D'], k=100000)
sns.histplot(data=distribution, shrink=.8)
<AxesSubplot:ylabel='Count'>
../../_images/intro_5_1.png

Weighted#

distribution = random.choices(['A','B', 'C', 'D'], weights=[1,1,1,2], k=100000)
sns.histplot(data=distribution, shrink=.8)
<AxesSubplot:ylabel='Count'>
../../_images/intro_7_1.png

Gaussian#

distribution = [random.gauss(0, 2) for _ in range(1000000)]
sns.histplot(data=distribution)
<AxesSubplot:ylabel='Count'>
../../_images/intro_9_1.png

Others#

distribution = [random.triangular() for _ in range(1000000)]
sns.histplot(data=distribution)
<AxesSubplot:ylabel='Count'>
../../_images/intro_11_1.png
distribution = [random.betavariate(1,2) for _ in range(1000000)]
sns.histplot(data=distribution)
<AxesSubplot:ylabel='Count'>
../../_images/intro_12_1.png
distribution = [random.expovariate(1) for _ in range(1000000)]
sns.histplot(data=distribution)
<AxesSubplot:ylabel='Count'>
../../_images/intro_13_1.png