View on GitHub

reading-notes

Daily Reading 6

Ten Thousand 1

How can the random module be utilized in Python to generate random numbers or make selections from a list, and what are some common functions available within the module?

The random module is a built in feature of python, but for coder convenience and for reducing the filesize for programs where it is unneeded, it must be imported manually by including

import random

at the top of your code.

The random library will give you access to numerous functions that provide you with semi-random seeded values. There are many included, but there are 5 that stand out as commonly useful.

random.randint(x,y) gives you a whole number that is between the provided x and y value, inclusive.

random.random() takes no arguments, and returns a float value somewhere between 0 and 1 inclusive. Note that this value can be very specific, returning values such as 0.15893716742544, which also means that doing a strictly equals check against random producing a specific number will (for practical purposes) always fail.

random.choice(collection) choice picks one element in a tuple, list or any other set object that is classified as a “collection object.” Think of it as drawing names from a hat, choice will pick one item in the list at random and present it to you.

random.choices(collection, k) works like choice above, but returns a list containing k number of randomly selected entries. Note that random choices can pick the same thing multiple times, producing an output list such as

print(random.choices(['a','b','c'], 4))

['b','b','c','a']

random.shuffle(list) works only on lists, and returns the same list, with the elements in a randomized order. Be careful with this, as it does modify the original.

In the context of software development, what is risk analysis, and what are the key steps involved in conducting a risk analysis for a software project?

Risk analysis is the art of determining how likely it is for something to go wrong during the development of software, and how bad potential issues would be. There are no projects with infinite time or budget, so prioritization must occur with each project, which is one of the ways risk analysis can be useful. By determining in advance what aspects of the project bring potential risk, which risks are unavoidable, and planning your work around the results of the analysis, you can stop problems before they occur, or at the very least stop them before they reach the production phase.

the 4 key steps in analyzing risk are: Forecast: Ponder the situation and goals, and attempt to foresee reasonable worst case scenarios. Estimate: Should the risk you’ve found come to pass, how much of a problem would it be for you and the company? Is it negligible, or disastrous? Decide: How big of a response is warranted from the risk presented? How much resources and hours should be distributed to prevention? Avoid: With an action plan established, achieve what you can to minimize the risk of worst potential disasters.

What is test coverage and why is it an important (or potentially misleading) metric in software testing?

Test coverage is a vague measure of the number of possible situations your program has tests run on before it is approved for production, as a %. With data science, it’s very frequently tempting to try and condense large problems into a singular index, that way you can look and go “big number good, small number bad” without a second thought. Things are rarely that simple though, and, tying into risk discussed above, what point is there in making a dozen tests for potential user actions that would ultimately be inconsequential?

Big O notation is a standardized notation that serves the purpose of illustrating at a glance how a program/function/method performs under a worst case scenario, and how that performance, time wise and space wise, changes over time in relation to handling larger lists, deeper nesting, or further burdens of any kind.

A real world comparison for an activity that takes O(n) could be carefully and thoroughly hand washing dishes. The more dishes you have, the longer you have to spend cleaning them one by one.

A dishwasher that can hold all of the dishes in the house would have a time big O of O(1), as once you power it on, it takes the same amount of time to clean whether it has 1 or 100 dishes inside.

Back To Main Page.