#random_demo.py import random # random for i in range(10): print(random.random()) # random real number in range [0,1). uniform distribution for i in range(10): print(random.random()*100) # [0,100) # randomint for i in range(10): print(random.randint(10,20), end=" ") # random int between 10 and 20, inclusive print() # choice hand = ['rock','paper','scissors'] for i in range(10): print(random.choice(hand)) #randomly one of the list items # choices letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m',\ 'n','o','p','q','r','s','t','u','v','w','x','y','z'] for i in range(10): print(random.choices(letters,k=random.randint(1,10))) #randomly some (1-10) of the list items #dups possible # shuffle random.shuffle(letters) #in-place shuffle a list print(letters) letters.sort() #print(letters) # normalvariate for i in range(10): print(random.normalvariate(100,10)) #normally distributed, (mean,stddev) for i in range(10): print(round(random.normalvariate(100,10)), end=" ") print()