Aloha Protocol


In [7]:
import random

n = 15  # number of users
frames = 1000 # number of frames sent
probs = [0.1, 0.2 ,0.3 ,0.4 , 0.5 , 0.6 , 0.7 , 0.8 , 0.9] #probabilities of sending
print("Using",frames,"frames and",n,"users...")

for p in probs:
    success = 0
    for frame in range(frames):
        numSent = 0
        for user in range(n):
            sendProb = random.random()
            if sendProb < p:
                numSent += 1
        if numSent == 1:
            success += 1

    print("Using p of",p,"there were",str((success/frames)*100) + "%","successful frames")


Using 1000 frames and 15 users...
Using p of 0.1 there were 37.4% successful frames
Using p of 0.2 there were 13.5% successful frames
Using p of 0.3 there were 3.0% successful frames
Using p of 0.4 there were 0.1% successful frames
Using p of 0.5 there were 0.0% successful frames
Using p of 0.6 there were 0.0% successful frames
Using p of 0.7 there were 0.0% successful frames
Using p of 0.8 there were 0.0% successful frames
Using p of 0.9 there were 0.0% successful frames