 # randoms

May 16th, 2021
597
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import random
2. import math
3.
4. #RANDOMLY GENERATE 100 INTEGERS AND STORE IN X
5. #we use the random function to generate these numbers and append them to the empty array x
6. x = []
7. for i in range(10000):
8.     x.append(random.randint(1, 200))
9.
10. #SAMPLE 100 NUMBERS RANDOMLY FROM X
11. #x has 10,000 items. indexed at 0 - 9,999. to sample randomly from x, we just have to
12. #pick from these numbers randomly using our random generator to generate an index.
13.
14. meen = []
15. for i in range(50000):
16.     mean_array = []
17.     loop_index = []
18.     #sample function
19.     for i in range(100):
20.         #get random index by randomly going through the indices
21.         random_index = random.randint(0, 9999)
22.
23.         #do this continuously until you get random index not seen in previous iteration
24.         while random_index in loop_index:
25.             random_index = random.randint(0,9999)
26.         #store random index so that we can check on next iteration if same index is generated again.
27.         loop_index.append(random_index)
28.
29.         #save these indices in mean array
30.         mean_array.append(x[random_index])
31.
32.     #remember to compute mean
33.     total = 0
34.     for i in range(len(mean_array)):
35.         total += mean_array[i]
36.     avg = total/len(mean_array)
37.     meen.append(avg)
38. meen.sort()
39. #print(meen)
40.
41. frq = 
42.
43. #we are dealing with special characters between 85 - 115
44. #we will go through the array called meen
45. #each character we see, we will check which number it is. and then we will count the frequency.
46.
47. #check the numbers. if number less than 85 or greater than 115, ignore.
48. #if number is between 85 - 115 do the following:
49. #if number is 85.xx, we will round up to 85.
50. #we will count number and all other 85.xx numbers.
51. #once we hit 86, we will start new count.
52.
53. frq_index = 0
54. last_seen = 85
55. for i in range(50000):
56.
57.     if meen[i] >= 85 and meen[i] <= 116:
58.         num = math.floor(meen[i])
59.         #check if number has been seen before.
60.         if num == last_seen:
61.             #this means the number has been seen before.
62.             frq[frq_index] += 1
63.
64.         else:
65.             #number has not been seen before
66.             #determine the difference between this number and last seen
67.             #know how many zeroes to add
68.             zeroes = num - last_seen
69.             for i in range(zeroes):
70.                 frq.append(0)
71.             frq_index += zeroes
72.             last_seen += zeroes
73.             frq[frq_index] += 1
74.
75. print(frq)
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
RAW Paste Data