Notes:

  • A library is a collection of code from an external source that can be used to add functionality to a program.
  • Randomization generates a value between two numbers. For example RANDOM(1,3) may result as 1 or 2 or 3, either one of those.
  • Method | Description

    seed() | Initialize the random number generator

    getstate() | Returns the current internal state of the random number generator

    setstate() | Restores the internal state of the random number generator

    getrandbits() | Returns a number representing the random bits

    randrange() | Returns a random number between the given range

    randint() | Returns a random number between the given range

    choice() | Returns a random element from the given sequence

    choices() | Returns a list with a random selection from the given sequence

    shuffle() | Takes a sequence and returns the sequence in a random order

    sample() | Returns a given sample of a sequence

    random() | Returns a random float number between 0 and 1

    uniform() | Returns a random float number between two given parameters

    betavariate() | Returns a random float number between 0 and 1 based on the Beta distribution (used in statistics)

    expovariate() | Returns a random float number based on the Exponential distribution (used in statistics)

    gammavariate() | Returns a random float number based on the Gamma distribution (used in statistics)

    gauss() | Returns a random float number based on the Gaussian distribution (used in probability theories)

    lognormvariate() | Returns a random float number based on a log-normal distribution (used in probability theories)

    normalvariate() | Returns a random float number based on the normal distribution (used in probability theories)

    vonmisesvariate() | Returns a random float number based on the von Mises distribution (used in directional statistics)

    paretovariate() | Returns a random float number based on the Pareto distribution (used in probability theories)

    weibullvariate() | Returns a random float number based on the Weibull distribution (used in statistics)

Hacks:

Lesson 3.14.1

import math

number = input("Insert the number that you want to find the greatest common divisor of")
def gcdfunction(number):
    result = math.gcd(int(number))
    return result

print("The greatest common divisor is: " + str(gcdfunction(number)))
The greatest common divisor is: 20

First the library math is used and imported to ensure that the math functions are able to be used. Then the variable number is set where a person inputs the number that they wish to take the greatest common divisor of. A function is then defined with a result variable that is set equal to the greatest common divisor of the integer that the user input. The result is then returned and printed in the sentence stating what the greatest common divisor.

Lesson 3.15.1

  1. Define what an import random function does

    An import random function generatees a random number that can be used in the function

  2. List a few other things that we can import other than random

    • math
    • flask
    • Numpy
    • TensorFlow
    • SciPy
    • own files

Lesson 3.15.2

  • There is a spinner divided into eight equal parts. 3 parts of the spinner are green, two parts are blue, one part is purple, one part is red, and one part is orange. How can you simulate this situation using a random number generator.
import random

spinner_lands = random.randint(1, 8)
if spinner_lands <= 3:
    color = "green"
elif spinner_lands <= 5:
    color = "blue"
elif spinner_lands <= 6:
    color = "purple"
elif spinner_lands <= 7:
    color = "red"
elif spinner_lands <= 8:
    color = "orange"

print("The color you landed on is: ", color)
The color you landed on is:  green
  • What numbers can be outputted from RANDOM(12,20) and what numbers are excluded?

The numbers that can be outputted are any number from 12 to 20 including 12 and 20.