Some interesting interview Q&A around “randomness”

import numpy as np
np.random.randint(0, len(stream_data))
import random
random.randint(0, len(stream_data))
def select_rand(big_stream):
rand_element = None
for i, e in enumerate(big_stream):
if i == 0: # could have been if(len(big_Stream)==0),hold on!
rand_element = e
return rand_element
random.randint(1, i+1) == 1 
import random

def select_rand(big_stream):
rand_element = None

for i, e in enumerate(big_stream):
if i == 0:
rand_element = e
if random.randint(1, i + 1) == 1:
rand_element = e
return rand_element
import numpy as np
from collections import Counter
N = 1000
Counter(np.random.randint(1,6,N) + np.random.randint(1,6,N)//2)
# Counter({1: 392, 7: 847, 3: 2007, 2: 1209, 6: 1570, 5: 1973, 4: 2002})

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store