Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import math
- #RANDOMLY GENERATE 10000 INTEGERS AND STORE IN X
- #we use the random function to generate these numbers and append them to the empty array x
- x = []
- for i in range(10000):
- x.append(random.randint(1, 200))
- #SAMPLE 100 NUMBERS RANDOMLY FROM X
- #x has 10,000 items. indexed at 0 - 9,999. to sample randomly from x, we just have to
- #pick from these numbers randomly using our random generator to generate an index.
- meen = []
- for i in range(50000):
- mean_array = []
- loop_index = []
- #sample function
- for i in range(100):
- #get random index by randomly going through the indices
- random_index = random.randint(0, 9999)
- #do this continuously until you get random index not seen in previous iteration
- while random_index in loop_index:
- random_index = random.randint(0,9999)
- #store random index so that we can check on next iteration if same index is generated again.
- loop_index.append(random_index)
- #save these indices in mean array
- mean_array.append(x[random_index])
- #remember to compute mean
- total = 0
- for i in range(len(mean_array)):
- total += mean_array[i]
- avg = total/len(mean_array)
- meen.append(avg)
- meen.sort()
- #print(meen)
- frq = [0]
- #we are dealing with special characters between 85 - 115
- #we will go through the array called meen
- #each character we see, we will check which number it is. and then we will count the frequency.
- #check the numbers. if number less than 85 or greater than 115, ignore.
- #if number is between 85 - 115 do the following:
- #if number is 85.xx, we will round up to 85.
- #we will count number and all other 85.xx numbers.
- #once we hit 86, we will start new count.
- frq_index = 0
- last_seen = 85
- for i in range(50000):
- if meen[i] >= 85 and meen[i] < 116:
- num = math.floor(meen[i])
- #check if number has been seen before.
- if num == last_seen:
- #this means the number has been seen before.
- frq[frq_index] += 1
- else:
- #number has not been seen before
- #determine the difference between this number and last seen
- #know how many zeroes to add
- zeroes = num - last_seen
- for i in range(zeroes):
- frq.append(0)
- frq_index += zeroes
- last_seen += zeroes
- frq[frq_index] += 1
- print(frq)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement