<commit_before>#!/usr/bin/env python
# coding=utf-8

def lcm(a, c, m, x0):
    """
    Linear Congruential Method to generate random number

    Xn+1 = (aXn + c) % m
    Rn = Xn/(float(m))

    Parameters:
    -----------
    (parameters see introduction of this function)
    a: 
    c:
    m:
    X0:

    Return:
    -------
    Rn: random number
    """
    Rn = []
    x_list = []
    x_list.append(x0)
    r = x0/float(m)
    while r not in Rn:
        Rn.append(r)
        x_list.append((a*x_list[-1] + c) % m)
        r = x_list[-1]/float(m)
    return Rn, x_list

if __name__ == "__main__":
    a = 9
    m = 16
    c = [0, 3]
    x0 = [1, 2, 3, 4]

    Rn = []
    X_list = []
    for ci in c:
        for xi in x0:
            r, x_list = lcm(a, ci, m, xi)
            Rn.append(r)
            X_list.append(x_list)
    
        






<commit_msg>generate random number for queue question<commit_after>#!/usr/bin/env python
# coding=utf-8

import math
import numpy as np

def lcm_bs(a, c, m, X):
    """
    """
    X_new = (a*X+c) % m
    R = X/float(m)
    return X_new, R

def lcm(a, c, m, X0):
    """
    A function to use Linear Congruential Method (LCM) to generate random number
    Here we use generator to make it faster and clearer.
    
    LCM: Xn+1 = (aXn+c) mod m
         Rn = Xn/float(m)

    Parameters:
    -----------
    a, c, m, X0   parameters

    Return:
    -------
    R: generator of random number
    """
    X_new = X0
    while 1:
        X_new, R = lcm_bs(a, c, m, X_new)
        yield R, X_new

def neg_exp_distribute(mean_time, U):
    """
    Generate series satisfied negative exponential distribution

    X = -mean*lnU
    
    Parameters:
    -----------
    mean_time: mean time
    U: a list as a parameter for negative exponential time

    Return:
    -------
    X: Generated time (interarrival time or service time)
    """
    return [-1.0*mean_time*math.log(u) for u in U]


if __name__ == '__main__':

    h_count = 5

    x0_iat = 1155192169
    # interarrival time series
    iat_gen = lcm(16807, 0, 2147483647, x0_iat)
    # generate first 50 random numbers and Xn (Xn will contains 51 numbers)
    iat_rd = [iat_gen.next() for i in range(h_count-1)]

    xn_iat = [j for i, j in iat_rd]
    u0_iat = 1.0*x0_iat/2147483647
    un_iat = [1.0*x/2147483647 for x in xn_iat]
    un_iat = [u0_iat] + un_iat

    iat = neg_exp_distribute(5, un_iat)
        
    x0_st = 1806794933
    # serice time series
    st_gen = lcm(16807, 0, 2147483647, 1806794933)
    # generate first 50 random numbers and Xn (Xn will contains 51 numbers) 
    st_rd = [st_gen.next() for i in range(h_count-1)]
    
    xn_st = [j for i, j in st_rd]
    u0_st = 1.0*x0_st/2147483647
    un_st = [1.0*x/2147483647 for x in xn_st]
    un_st = [u0_st] + un_st

    st = neg_exp_distribute(8, un_st)
    
#    queue_time_series = []
#     # the average time in queue
#     for i in np.arange(1, len(iat)):
#         queue_time_series.append(sum(st[:i]) - sum(iat[:(i+1)]))
     
     
    # the average time being serviced
    avg_st_time = np.mean(st)    

    # the average time in system
    if np.sum(iat) < np.sum(st[:-2]):
        avg_time = (np.sum(st) + iat[0])/len(iat)
    else:
        avg_time = (np.sum(iat) + st[-1])/len(iat)
   





{'fraction_non_alphanumeric': 0.13483831604636973, 'fraction_numerical': 0.050030506406345335, 'mean_word_length': 1.967420814479638, 'pattern_counts': {'":': 1, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1256941', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1289, 'n_words': 352}