Skip to content

Instantly share code, notes, and snippets.

@mattwthompson
Created September 17, 2018 15:15
Show Gist options
  • Save mattwthompson/33bf0c2952ee6bf49e12c5d394c74623 to your computer and use it in GitHub Desktop.
Save mattwthompson/33bf0c2952ee6bf49e12c5d394c74623 to your computer and use it in GitHub Desktop.
import random
import numpy as np
composition = [1/3, 1/3, 1/3]
sites = np.zeros(shape=(300,))
val_1 = composition[2] + composition[1]
val_2 = composition[2]
val_3 = 0
for i, site in enumerate(sites):
val = random.random()
if val > val_1:
sites[i] = 1
elif val > val_2:
sites[i] = 2
elif val > val_3:
sites[i] = 3
for val in range(4):
print(val, len(np.where(sites == val)[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment