Screen Link:

https://app.dataquest.io/m/99/chi-squared-tests/4/generating-a-distribution

My Code:

```
chi_squared_values = []
from numpy.random import random
import matplotlib.pyplot as plt
count_male=0
count_female=0
expected=16280.5
for i in range (1000):
vector=random((32561,))
for num in vector:
if num<0.5:
count_male+=1
else:
count_female+=1
male_diff=(count_male-expected)**2/expected
female_diff=(count_female-expected)**2/expected
chi_squared=male_diff+female_diff
chi_squared_values.append(chi_squared)
plt.hist(chi_squared_values)
```

What I expected to happen:

What actually happened:

Solution code:

```
chi_squared_values = []
from numpy.random import random
import matplotlib.pyplot as plt
for i in range(1000):
sequence = random((32561,))
sequence[sequence < .5] = 0
sequence[sequence >= .5] = 1
male_count = len(sequence[sequence == 0])
female_count = len(sequence[sequence == 1])
male_diff = (male_count - 16280.5) ** 2 / 16280.5
female_diff = (female_count - 16280.5) ** 2 / 16280.5
chi_squared = male_diff + female_diff
chi_squared_values.append(chi_squared)
plt.hist(chi_squared_values)
```

Looking at the solution code I’m quite aware that I didn’t take the best approach to generate the distribution, but I can’t see where the logic is wrong. Can anyone show me please?

Thx in advance =)