2020-11-09 12:49:27 One stop

```"""
Priority connection model ：

A series of objects （ people ） Arrive one by one . The first arrival creates an entity . The following rules apply every time someone arrives ：
In probability p（ smaller ） Under the circumstances , The new arrival creates a new entity ; In probability （1-p） Under the circumstances , New arrivals join an existing entity （ Generate links ）.
The probability of adding a particular entity is equal to the size of the entity divided by the number of all arrivals so far .
"""

import random
import matplotlib.pyplot as plt

#  Initialize variable
network = {0:}
nodes = 1000
p = 0.1
num = 1

for i in range(1, nodes):
network[i] = []
x = random.random()
accu_prob = 0.0
num += 1

#  If the probability is less than the initial probability, a new entity will be created
if x <= p:
network[i] = 
else:
#  On the contrary, it traverses value Calculate the probability of each entity
for key,value in network.items():
accu_prob += len(value) / num
if x <= accu_prob:
network[key].append(1)
break

node_list = [len(value) for value in network.values()]

plt.hist(node_list, 50)
plt.show()``` 