import random


def get_network_demands(network_topology, num):
    """
    Generates a list of network demands on the provided network topology
    :param network_topology: type tuple
        Tuple of networkx.Graphs that describe the communication resources and connectivity of quantum network
    :param num: type int
        The number of demands desired
    :return: type list
        List of tuples (source, destination, fidelity, rate) describing the demand
    """
    _, nodeG = network_topology
    demands = []
    end_nodes = [node for node in nodeG.nodes if nodeG.nodes[node]["end_node"] is True]
    for num_demands in range(num):
        src, dst = random.sample(end_nodes, 2)
        fidelity = round(0.6 + random.random() * (3 / 10), 3)                    # Fidelity range between F=0.6 and 1
        rate = 10 / (2**random.choice([i for i in range(7, 11)]))       # Rate range between 0.2 and 1
        demands.append((src, dst, fidelity, rate))
    return demands