#!/usr/bin/python
# This script is used to generate the input files for both "Vector Clock" and
# "Causal Multicast" automatically. The script will generate input_vector.txt
# input_causal.txt two files in the working directory.
#
# usage: input.py client_num line_num
#
# Liang Wang @ Dept. Computer Science, University of Helsinki
# 2011.02.02
#

import os
import sys
import math
import random

def vector_clock(c, l):
    s = ""
    for i in range(l):
        t = random.sample(c, 2)
        if random.random() < 0.8:
            s += "%i M %i\n" % (t[0], t[1])
        else:
            s += "%i L %i\n" % (t[0], random.randint(1, 10))
    return s

def causal(c, l):
    s = ""
    for i in range(l):
        if random.random() < 0.7:
            s += "%i\n" % (random.sample(c, 1)[0])
        else:
            t = random.sample(c, random.randint(1, math.ceil((len(c)*0.7))))
            s += "|".join([str(x) for x in t]) + "\n"
    return s

if __name__=="__main__":
    c, l = int(sys.argv[1]), int(sys.argv[2])
    open("input_vector.txt", "w").write(vector_clock(range(1, c+1), l))
    open("input_causal.txt", "w").write(causal(range(1, c+1), l))
