from random import randint

class Fausse_Liste:  # Pour l'affichage
    def __init__(self):
        self.l = []
    
    def __len__(self):
        return len(self.l)
    
    def __repr__(self):  # Vraiment pas top, mais cohérent avec le sujet...
        return "| " + " | ".join(str(x) for x in self.l) + " <- tête"
    
    def append(self, x):
        self.l.append(x)
        
    def pop(self, i):
        return self.l.pop(i)


def cree_file():
    return Fausse_Liste()

def est_vide(f):
    return len(f) == 0

def enfile(f, x):
    f.append(x)

def defile(f):
    return f.pop(0)


class Routeur_DROP_TAIL:
    def __init__(self, t_max):
        self.f = cree_file()
        self.t_max = t_max
        self.t = 0
        
    def recoit(self, p):
        if self.t < self.t_max:
            enfile(self.f, p)
            self.t = self.t + 1
            return True
        return False
    
class Routeur_ALEA:
    def __init__(self, t_min, t_max):
        self.f = cree_file()
        self.t_min = t_min
        self.t_max = t_max
        self.t = 0
    
    def tirage_au_sort(self):
        """True ou False"""
        return randint(0, 1) == 1
    
    def recoit(self, p):
        if self.t < self.t_min:
            enfile(self.f, p)
            self.t = self.t + 1
            return True
        elif self.t_min <= self.t < self.t_max:
            if self.tirage_au_sort():
                enfile(self.f, p)
                self.t = self.t + 1
                return True
        return False
    