""" Purpose: introduce some functions from module random """ # by default the random module produces different interactions every time we use it import random # get access to random functions and capabilities by importing this module # in this class, you will only be using choice(), seed(), and randrange() # you will ALWAYS need to import random for using these functions ### get four integers reply = input( "Enter four integers: " ) m1, n1, m2, n2 = reply.split() m1 = int( m1 ) # casting the strings to numbers ( handed back from input() so they are strings ) n1 = int( n1 ) m2 = int( m2 ) n2 = int( n2 ) # random function randrange( x, y ) returns random integer from interval # x to y-1; which is written MATHEMATICALLY as [ x, y ) # **like nearly every other operation (range(), [:], etc., we go from x to y-1 / [ x, y )** i1 = random.randrange( m1, n1 ) i2 = random.randrange( m1, n1 ) i3 = random.randrange( m1, n1 ) i4 = random.randrange( m1, n1 ) j1 = random.randrange( m2, n2 ) j2 = random.randrange( m2, n2 ) j3 = random.randrange( m2, n2 ) j4 = random.randrange( m2, n2 ) print() print( "Four random values from [", m1, ",", n1, "):", i1, i2, i3, i4 ) print( "Four random values from [", m2, ",", n2, "):", j1, j2, j3, j4 ) print() # rachel added this for her own sanity ### get two integers reply = input( "Enter two integers: " ) n1, n2 = reply.split() n1 = int( n1 ) n2 = int( n2 ) # random function randrange( b ) when a given a single integer argument returns # random integer from 0 to b-1. The value is also called a base b integer # there are many applications of getting a random number between 0 and a number # for example, colors are represented using rgb values, r,g, and b can vary between 0-255 # we don't have to say ( 0, n ) starting at 0 is implied # this is also true for the range( n ) function! this will be a range from 0 to n-1 ; ( the range has a size n ) i1 = random.randrange( n1 ) i2 = random.randrange( n1 ) i3 = random.randrange( n1 ) i4 = random.randrange( n1 ) j1 = random.randrange( n2 ) j2 = random.randrange( n2 ) j3 = random.randrange( n2 ) j4 = random.randrange( n2 ) print() print( "Four random values from interval [ 0,", n1, " ):", i1, i2, i3, i4 ) print( "Four random values from interval [ 0,", n2, "):", j1, j2, j3, j4 ) print() # summary: random.randrange( i, j ) # returns a random number between i and ( j-1 ) -> number on the interval [ i, j ) # random.randrange( n ) # returns a random number between 0 and ( n-1 ) -> number on the interval [ 0, n ) # these values can be forced by setting a seed with random.seed() # there are many random number applications, they're all over video games for example!