In [ ]:
import numpy as np

N_SAMPLES = 100000

rng = np.random.default_rng(seed=42)
loaded_gun = np.array((1,1,0,0,0,0))

Let's now sample indexes (from 0 to 5) and see whether we survive

In [ ]:
sampled_position = rng.integers(low=0,high=5)

shoot = loaded_gun[sampled_position]

if shoot:
  print("BAM! You are dead! Sorry")
else:
  print("Pheew, you survived!")
BAM! You are dead! Sorry

Since we are drawing position at random, we would expect to die $\frac{2}{6}$ of the times, so $33\%$

In [ ]:
sampled_positions = rng.integers(low=0,high=6,size=N_SAMPLES)

shoots = loaded_gun[sampled_positions]

print("You died with a probability of roughly: ", sum(shoots)/len(shoots))
You died with a probability of roughly:  0.33169

Option 1: Rotating the Cylinder¶

In [ ]:
sampled_first_shoots = rng.integers(low=0,high=6,size=N_SAMPLES)
sampled_second_shoots = rng.integers(low=0,high=6,size=N_SAMPLES)

shoots = loaded_gun[sampled_first_shoots] + loaded_gun[sampled_second_shoots]

survive = shoots == 0

print("You survived with a probability of roughly: ", sum(survive)/len(survive))
You survived with a probability of roughly:  0.44456

Option 2: Not rotating the Cylinder¶

In [ ]:
sampled_first_shoots = rng.integers(low=0,high=6,size=N_SAMPLES)
second_shoots = (sampled_first_shoots + 1) % 6 # added the mod operation to wrap around

shoots = loaded_gun[sampled_first_shoots] + loaded_gun[second_shoots]

survive = shoots == 0

print("You survived with a probability of roughly: ", sum(survive)/len(survive))
You survived with a probability of roughly:  0.50164