Empire State Building Bet Flashcards
Use seed() to set the seed; as an argument, pass 123. Then, generate your first random float with rand() and print it out.
np.random.seed(123)
print(np.random.rand())
how do i generate integers randomly?
randint()
Use randint() with the appropriate arguments to randomly generate the integer 1, 2, 3, 4, 5 or 6. This simulates a dice
print(np.random.randint(1, 7))
If step = 50, use if-elif-else statement, If dice is 1 or 2, you go one step down. If dice is 3, 4 or 5, you go one step up. Else, you throw the dice again. The number on the dice is the number of steps you go up.
if dice <= 2 :
step = step - 1
elif dice <= 5 :
step = step+1
else :
step = step + np.random.randint(1,7)
print(dice)
print(step)
What is a random walk?
Succession of random steps, like financial status of a gambler
Specify the beginning of a for loop so that the random walk is simulated five times.
for i in range(5) :
After a random_walk array is entirely populated, how do you append it to the all_walks list?
all_walks.append(random_walk)
Convert all_walks to NumPy array: np_aw
np_aw = np.array(all_walks)
Plot np_aw and show
plt.plot(np_aw)
plt.show()
Transpose np_aw: np_aw_t
np_aw_t = np.transpose(np_aw)
Finish the if condition so that step is set to 0 if a random float is less or equal to 0.005. Use np.random.rand():
if ___:
step = 0
if np.random.rand() <= 0.005 :
step = 0