-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulation.py
586 lines (487 loc) · 21.8 KB
/
simulation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
import random
def findXorfile3(numberOfFile, numberOfClient, randomMatrix, randomAskFile, memorySizeRatio):
xorFilename = []
notXorFilename = []
numberOfSeperatefile = numberOfFile/memorySizeRatio
'''
print ''
print randomAskFile
print ''
'''
# indication of client x, just for simulation
clientSimu = 0
xorFileSimuFlag = []
notXorFileSimuFlag = []
# copy the randomMatrix to the copyRandomMatrix(because of pointer)
copyRandomMatrix = []
for i in range(0, len(randomMatrix), 1):
temp = []
for j in range(0, len(randomMatrix[i]), 1):
temp.append(randomMatrix[i][j])
copyRandomMatrix.append(temp)
# use to record which part of the ask file client has
tempMatrix = []
for i in range(0, numberOfClient, 1):
tempMatrix.append([])
# find the xor file from two client which has the same ask file
for sourceClient in range(0, numberOfClient, 1):
askFile = randomAskFile[sourceClient]
# begin to search the client after the sourceClient
for targetClient in range(sourceClient+1, len(randomAskFile), 1):
# askFile locate in the line 'askFile'
# compare the 'askFile' -------------------------------------------> True
# the cached file of the two client are not same-------------------> True
logicalResult = copyRandomMatrix[sourceClient][askFile] != copyRandomMatrix[targetClient][askFile]
if randomAskFile[targetClient] == askFile and logicalResult:
# askedOfSourceClient: the source client has which part of the ask file
# askedOfTargetClient: the target client has which part of the ask file
askedOfSourceClient = ','.join( tempMatrix[sourceClient] )
askedOfTargetClient = ','.join( tempMatrix[targetClient] )
# the two client do not have the part of ask file from each other
logicalResult_1 = askedOfSourceClient.find( copyRandomMatrix[targetClient][askFile] ) == -1
logicalResult_2 = askedOfTargetClient.find( copyRandomMatrix[sourceClient][askFile] ) == -1
if logicalResult_1 and logicalResult_2:
xorFilename.append( copyRandomMatrix[sourceClient][askFile] )
xorFilename.append( copyRandomMatrix[targetClient][askFile] )
tempMatrix[sourceClient].append( copyRandomMatrix[targetClient][askFile] )
tempMatrix[targetClient].append( copyRandomMatrix[sourceClient][askFile] )
# for simulation
if sourceClient == clientSimu:
xorFileSimuFlag.append(True)
else:
xorFileSimuFlag.append(False)
# find the xor file from two client which has the different ask file
for sourceClient in range(0, numberOfClient, 1):
for cacheFile in range(0, numberOfFile, 1):
# get the file sequence number of the cachefile
# the cacheFile indicate the file sequence number
fileSequenNumber = cacheFile
cacheFileSourceClient = cacheFile
# tempMatrix record the part of the ask file which already have
# if the file sequence number is the same as the ask file of client, record it
# and we do not need to search the matrix, because we have done this before
# only if the file sequence number is not same as the ask file of client, you search the matrix
if fileSequenNumber == randomAskFile[sourceClient]:
tempMatrix[sourceClient].append(copyRandomMatrix[sourceClient][cacheFile])
else:
# search the client after the source client
for targetClient in range(sourceClient+1, numberOfClient, 1):
askFileOfTarg = randomAskFile[targetClient]
# if the target client ask the 'cacheFileSourceClient'
# we may be can find the xor file
if askFileOfTarg == cacheFileSourceClient:
askFileOfSour = randomAskFile[sourceClient]
# the target(xor) file of each client muss not be owned by the other
# fLogR -> first logical result ; sLogR -> second logical result
fLogR = copyRandomMatrix[targetClient][askFileOfSour] != copyRandomMatrix[sourceClient][askFileOfSour]
sLogR = copyRandomMatrix[targetClient][askFileOfTarg] != copyRandomMatrix[sourceClient][askFileOfTarg]
if fLogR and sLogR:
# askedOfSourceClient: the source client has which part of the ask file
# askedOfTargetClient: the target client has which part of the ask file
askedOfSourceClient = ','.join(tempMatrix[sourceClient])
askedOfTargetClient = ','.join(tempMatrix[targetClient])
# the two client do not have the part of ask file from each other
fLogR = askedOfSourceClient.find( copyRandomMatrix[targetClient][askFileOfSour] ) == -1
sLogR = askedOfTargetClient.find( copyRandomMatrix[sourceClient][askFileOfTarg] ) == -1
if fLogR and sLogR:
xorFilename.append( copyRandomMatrix[sourceClient][askFileOfTarg] )
xorFilename.append( copyRandomMatrix[targetClient][askFileOfSour] )
tempMatrix[sourceClient].append( copyRandomMatrix[targetClient][askFileOfSour] )
tempMatrix[targetClient].append( copyRandomMatrix[sourceClient][askFileOfTarg] )
# for simulation
if sourceClient == clientSimu:
xorFileSimuFlag.append(True)
else:
xorFileSimuFlag.append(False)
'''
print 'tempMatrix,after sending the XOR file, the client has this file of his asking file:'
print ''
length = len(tempMatrix)
print ""
for i in range(0,length,1):
print 'client' + str(i)+': '+str(randomAskFile[i])+' '+str(tempMatrix[i])
print ""
'''
# creat a full matrix, which contains the whole ask file of every client
# use to compare with tempMatrix, then we can find out the not xor files
fullMatrix = []
for i in range(0, numberOfClient, 1):
fullMatrix.append([])
for i in range(0, numberOfClient, 1):
for j in range(0, numberOfSeperatefile, 1):
fullMatrix[i].append(str(randomAskFile[i]) + str(j))
# filenameMatrix is used to store the not xor files
# but filenameMatrix is a matrix, at last change it to vector
notXorFileSimuTemp = []
filenameMatrix = []
for i in range(0, numberOfFile, 1):
filenameMatrix.append([])
for i in range(0, numberOfClient, 1):
templist_1 = ','.join(filenameMatrix[randomAskFile[i]])
templist_2 = ','.join(tempMatrix[i])
for j in range(0, numberOfSeperatefile, 1):
if templist_1.find(fullMatrix[i][j]) == -1 and templist_2.find(fullMatrix[i][j]) == -1:
filenameMatrix[randomAskFile[i]].append(fullMatrix[i][j])
# for simulation
if i == clientSimu:
notXorFileSimuTemp.append(fullMatrix[i][j])
# store the not xor files from matrix(filenameMatrix) to vector(notXorFilename)
for i in range(0, len(filenameMatrix), 1):
for j in range(0, len(filenameMatrix[i]), 1):
notXorFilename.append(filenameMatrix[i][j])
# for simulation
if ','.join(notXorFileSimuTemp).find(filenameMatrix[i][j]) != -1:
notXorFileSimuFlag.append(True)
else:
notXorFileSimuFlag.append(False)
'''
print ''
print 'this files will be XOR: '
print xorFilename
print ''
print 'this files will not be XOR:'
print notXorFilename
print ''
'''
return xorFilename, notXorFilename#, xorFileSimuFlag, notXorFileSimuFlag
def randomfile(fileNumber, numberOfClient, seperateNumber):
#print 'fileNumber, seperateNumber',fileNumber, seperateNumber
randomMatrix = []
tempRange = range(0, seperateNumber, 1)
for i in range(0, numberOfClient, 1):
matrixElement = []
#tempRandom = random.sample(tempRange, seperateNumber)
tempRandom = random.sample(tempRange, 1)
for j in range(0, fileNumber, 1):
matrixElement.append(str(j) + str(tempRandom[0]))
randomMatrix.append(matrixElement)
length = len(randomMatrix)
'''
print ""
for i in range(0,length,1):
print 'client' + str(i)+': '+str(randomMatrix[i])
print ""
'''
return randomMatrix
def findXorfile(fileNumber, numberOfClient, randomMatrix,randomAskFile,seperateNumber):
xorFilename = []
filename = []
'''
print ''
print randomAskFile
print ''
'''
#copy the randomMatrix to the copyRandomMatrix(because of pointer)
copyRandomMatrix = []
for i in range(0, len(randomMatrix), 1):
temp = []
for j in range(0, len(randomMatrix[i]), 1):
temp.append(randomMatrix[i][j])
copyRandomMatrix.append(temp)
#===========================
#use to record the client has which part of the asked file
tempMatrix = []
for i in range(0, numberOfClient, 1):
tempMatrix.append([])
#find the xor find between the user with the same asking file
for i in range(0, numberOfClient, 1):
temp = randomAskFile[i]
for j in range(i, len(randomAskFile), 1):
# the client has the same asked file and the cached file of the asking file is not the same
if randomAskFile[j] == temp and (copyRandomMatrix[i][randomAskFile[i]] != copyRandomMatrix[j][randomAskFile[i]]):
tempdata_1 = ','.join(tempMatrix[i])
tempdata_2 = ','.join(tempMatrix[j])
#judge if one of them has the cached file from the other
if not (tempdata_1.find(copyRandomMatrix[j][randomAskFile[i]]) > -1 or tempdata_2.find(copyRandomMatrix[i][randomAskFile[i]]) > -1):
xorFilename.append(copyRandomMatrix[i][randomAskFile[i]])
xorFilename.append(copyRandomMatrix[j][randomAskFile[i]])
tempMatrix[j].append(copyRandomMatrix[i][randomAskFile[i]])
tempMatrix[i].append(copyRandomMatrix[j][randomAskFile[i]])
for i in range(0, numberOfClient, 1):
for j in range(0, fileNumber, 1):
if copyRandomMatrix[i][j][0] == str(randomAskFile[i]):
tempMatrix[i].append(copyRandomMatrix[i][j])
for l in range(0, len(randomAskFile), 1):
if randomAskFile[l] == int(copyRandomMatrix[i][j][0]):
row = l
temp1 = copyRandomMatrix[row][randomAskFile[i]][0]
temp2 = copyRandomMatrix[i][randomAskFile[i]][0]
if copyRandomMatrix[row][randomAskFile[i]] != copyRandomMatrix[i][randomAskFile[i]] and copyRandomMatrix[row][j] != copyRandomMatrix[i][j]:
tempdata = ','.join(xorFilename)
tempdata_1 = ','.join(tempMatrix[row])
tempdata_2 = ','.join(tempMatrix[i])
#if tempdata.find(copyRandomMatrix[i][j])==-1 or tempdata.find(copyRandomMatrix[row][randomAskFile[i]])==-1:
if not (tempdata_1.find(copyRandomMatrix[i][j]) > -1 or tempdata_2.find(copyRandomMatrix[row][randomAskFile[i]]) > -1):
xorFilename.append(copyRandomMatrix[i][j])
xorFilename.append(copyRandomMatrix[row][randomAskFile[i]])
tempMatrix[row].append(copyRandomMatrix[i][j])
tempMatrix[i].append(copyRandomMatrix[row][randomAskFile[i]])
#break
'''
print 'tempMatrix,after sending the XOR file, the client has this file of his asking file:'
print ''
length = len(tempMatrix)
print ""
for i in range(0,length,1):
print 'client' + str(i)+': '+str(randomAskFile[i])+' '+str(tempMatrix[i])
print ""
'''
fullMatrix = []
for i in range(0, numberOfClient, 1):
fullMatrix.append([])
for i in range(0, numberOfClient, 1):
for j in range(0, seperateNumber, 1):
fullMatrix[i].append(str(randomAskFile[i]) + str(j))
#print 'fullMatrix'
#print fullMatrix
filenameMatrix = []
for i in range(0, fileNumber, 1):
filenameMatrix.append([])
for i in range(0, numberOfClient, 1):
templist_1 = ','.join(filenameMatrix[randomAskFile[i]])
templist_2 = ','.join(tempMatrix[i])
for j in range(0, seperateNumber, 1):
if templist_1.find(fullMatrix[i][j]) == -1 and templist_2.find(fullMatrix[i][j]) == -1:
filenameMatrix[randomAskFile[i]].append(fullMatrix[i][j])
#print 'filenameMatrix'
#print filenameMatrix
for i in range(0, len(filenameMatrix), 1):
for j in range(0, len(filenameMatrix[i]), 1):
filename.append(filenameMatrix[i][j])
'''
print ''
print 'this files will be XOR: '
print xorFilename
print ''
print 'this files will not be XOR:'
print filename
print ''
#print 'copyRandomMatrix will be:'
#print copyRandomMatrix
'''
return xorFilename, filename
def findXorfile2(numberOfFile, numberOfClient, randomMatrix, randomAskFile, memorySizeRatio):
xorFilename = []
notXorFilename = []
numberOfSeperatefile = numberOfFile/memorySizeRatio
# indication of client x, just for simulation
clientSimu = 0
xorFileSimuFlag = []
notXorFileSimuFlag = []
# copy the randomMatrix to the copyRandomMatrix(because of pointer)
copyRandomMatrix = []
for i in range(0, len(randomMatrix), 1):
temp = []
for j in range(0, len(randomMatrix[i]), 1):
temp.append(randomMatrix[i][j])
copyRandomMatrix.append(temp)
# use to record which part of the ask file client has
tempMatrix = []
for i in range(0, numberOfClient, 1):
tempMatrix.append([])
# find the xor file from two client which has the same ask file
for sourceClient in range(0, numberOfClient, 1):
askFile = randomAskFile[sourceClient]
# begin to search the client after the sourceClient
for targetClient in range(sourceClient+1, len(randomAskFile), 1):
# askFile locate in the line 'askFile'
# compare the 'askFile' -------------------------------------------> True
# the cached file of the two client are not same-------------------> True
logicalResult = copyRandomMatrix[sourceClient][askFile] != copyRandomMatrix[targetClient][askFile]
if randomAskFile[targetClient] == askFile and logicalResult:
# askedOfSourceClient: the source client has which part of the ask file
# askedOfTargetClient: the target client has which part of the ask file
askedOfSourceClient = ','.join( tempMatrix[sourceClient] )
askedOfTargetClient = ','.join( tempMatrix[targetClient] )
# the two client do not have the part of ask file from each other
logicalResult_1 = askedOfSourceClient.find( copyRandomMatrix[targetClient][askFile] ) == -1
logicalResult_2 = askedOfTargetClient.find( copyRandomMatrix[sourceClient][askFile] ) == -1
if logicalResult_1 and logicalResult_2:
xorFilename.append( copyRandomMatrix[sourceClient][askFile] )
xorFilename.append( copyRandomMatrix[targetClient][askFile] )
tempMatrix[sourceClient].append( copyRandomMatrix[targetClient][askFile] )
tempMatrix[targetClient].append( copyRandomMatrix[sourceClient][askFile] )
# for simulation
if sourceClient == clientSimu:
xorFileSimuFlag.append(True)
else:
xorFileSimuFlag.append(False)
# find the xor file from two client which has the different ask file
for sourceClient in range(0, numberOfClient, 1):
for cacheFile in range(0, numberOfFile, 1):
# get the file sequence number of the cachefile
# the cacheFile indicate the file sequence number
fileSequenNumber = cacheFile
cacheFileSourceClient = cacheFile
# tempMatrix record the part of the ask file which already have
# if the file sequence number is the same as the ask file of client, record it
# and we do not need to search the matrix, because we have done this before
# only if the file sequence number is not same as the ask file of client, you search the matrix
if fileSequenNumber == randomAskFile[sourceClient]:
tempMatrix[sourceClient].append(copyRandomMatrix[sourceClient][cacheFile])
else:
# search the client after the source client
for targetClient in range(sourceClient+1, numberOfClient, 1):
askFileOfTarg = randomAskFile[targetClient]
# if the target client ask the 'cacheFileSourceClient'
# we may be can find the xor file
if askFileOfTarg == cacheFileSourceClient:
askFileOfSour = randomAskFile[sourceClient]
# the target(xor) file of each client muss not be owned by the other
# fLogR -> first logical result ; sLogR -> second logical result
fLogR = copyRandomMatrix[targetClient][askFileOfSour] != copyRandomMatrix[sourceClient][askFileOfSour]
sLogR = copyRandomMatrix[targetClient][askFileOfTarg] != copyRandomMatrix[sourceClient][askFileOfTarg]
if fLogR and sLogR:
# askedOfSourceClient: the source client has which part of the ask file
# askedOfTargetClient: the target client has which part of the ask file
askedOfSourceClient = ','.join(tempMatrix[sourceClient])
askedOfTargetClient = ','.join(tempMatrix[targetClient])
# the two client do not have the part of ask file from each other
fLogR = askedOfSourceClient.find( copyRandomMatrix[targetClient][askFileOfSour] ) == -1
sLogR = askedOfTargetClient.find( copyRandomMatrix[sourceClient][askFileOfTarg] ) == -1
if fLogR and sLogR:
xorFilename.append( copyRandomMatrix[sourceClient][askFileOfTarg] )
xorFilename.append( copyRandomMatrix[targetClient][askFileOfSour] )
tempMatrix[sourceClient].append( copyRandomMatrix[targetClient][askFileOfSour] )
tempMatrix[targetClient].append( copyRandomMatrix[sourceClient][askFileOfTarg] )
# for simulation
if sourceClient == clientSimu:
xorFileSimuFlag.append(True)
else:
xorFileSimuFlag.append(False)
'''
print 'tempMatrix,after sending the XOR file, the client has this file of his asking file:'
print ''
length = len(tempMatrix)
print ""
for i in range(0,length,1):
print 'client' + str(i)+': '+str(randomAskFile[i])+' '+str(tempMatrix[i])
print ""
'''
# creat a full matrix, which contains the whole ask file of every client
# use to compare with tempMatrix, then we can find out the not xor files
fullMatrix = []
for i in range(0, numberOfClient, 1):
fullMatrix.append([])
for i in range(0, numberOfClient, 1):
for j in range(0, numberOfSeperatefile, 1):
fullMatrix[i].append(str(randomAskFile[i]) + str(j))
# filenameMatrix is used to store the not xor files
# but filenameMatrix is a matrix, at last change it to vector
notXorFileSimuTemp = []
filenameMatrix = []
for i in range(0, numberOfFile, 1):
filenameMatrix.append([])
for i in range(0, numberOfClient, 1):
templist_1 = ','.join(filenameMatrix[randomAskFile[i]])
templist_2 = ','.join(tempMatrix[i])
for j in range(0, numberOfSeperatefile, 1):
if templist_1.find(fullMatrix[i][j]) == -1 and templist_2.find(fullMatrix[i][j]) == -1:
filenameMatrix[randomAskFile[i]].append(fullMatrix[i][j])
# for simulation
if i == clientSimu:
notXorFileSimuTemp.append(fullMatrix[i][j])
# store the not xor files from matrix(filenameMatrix) to vector(notXorFilename)
for i in range(0, len(filenameMatrix), 1):
for j in range(0, len(filenameMatrix[i]), 1):
notXorFilename.append(filenameMatrix[i][j])
# for simulation
if ','.join(notXorFileSimuTemp).find(filenameMatrix[i][j]) != -1:
notXorFileSimuFlag.append(True)
else:
notXorFileSimuFlag.append(False)
'''
print ''
print 'this files will be XOR: '
print xorFilename
print ''
print 'this files will not be XOR:'
print notXorFilename
print ''
'''
return xorFilename, notXorFilename#, xorFileSimuFlag, notXorFileSimuFlag
def main():
fileNumber = 8
numberOfClient = 6
#seperateNumber = numberOfClient / 2
totalLength = []
seperateNumber = numberOfClient
xorFilenameLength = 0
filenameLength = 0
xorFilenameLength2 = 0
filenameLength2 = 0
for j in range(0, 500, 1):
randomMatrix = randomfile(fileNumber, numberOfClient, seperateNumber)
randomAskFile = []
tempRange = range(0, fileNumber, 1)
for i in range(0, numberOfClient, 1):
temp = random.sample(tempRange, 1)
randomAskFile.append(temp[0])
xorFilename, filename = findXorfile(fileNumber, numberOfClient, randomMatrix, randomAskFile, seperateNumber)
xorFilenameLength = xorFilenameLength + len(xorFilename)
filenameLength = filenameLength + len(filename)
xorFilename2, filename2 = findXorfile2(fileNumber, numberOfClient, randomMatrix, randomAskFile, 1)
xorFilenameLength2 = xorFilenameLength2 + len(xorFilename2)
filenameLength2 = filenameLength2 + len(filename2)
if xorFilenameLength != xorFilenameLength2 or filenameLength != filenameLength2:
print 'error:'
print 'randomMatrix: ',randomMatrix
print 'randomAskFile: ',randomAskFile
print '\nfirst find: '
print 'xorFilename: ',xorFilename
print 'filename: ',filename
print '\nsecond find: '
print 'xorFilename2: ',xorFilename2
print 'filename2: ',filename2
xorFilenameLength = float(xorFilenameLength) / 2 / 500
filenameLength = float(filenameLength) / 500
xorFilenameLength2 = float(xorFilenameLength2) / 2 / 500
filenameLength2 = float(filenameLength2) / 500
print float(xorFilenameLength + filenameLength)/(fileNumber * seperateNumber)
print float(xorFilenameLength2 + filenameLength2)/(fileNumber * seperateNumber)
'''
for l in range(0, numberOfClient, 1):
xorFilenameLength = 0
filenameLength = 0
for j in range(0, 500, 1):
seperateNumber = numberOfClient / (l+1)
randomMatrix = randomfile(fileNumber, numberOfClient, seperateNumber)
randomAskFile = []
tempRange = range(0, fileNumber, 1)
for i in range(0, numberOfClient, 1):
temp = random.sample(tempRange, 1)
randomAskFile.append(temp[0])
xorFilename, filename = findXorfile(fileNumber, numberOfClient, randomMatrix, randomAskFile, seperateNumber)
xorFilenameLength = xorFilenameLength + len(xorFilename)
filenameLength = filenameLength + len(filename)
#print xorFilenameLength,filenameLength
xorFilenameLength = xorFilenameLength / 2 / 500
filenameLength = filenameLength / 500
#print xorFilenameLength,filenameLength
totalLength.append(float(xorFilenameLength + filenameLength)/(fileNumber * seperateNumber))
print totalLength
'''
if __name__ == "__main__":
main()
'''
for l in range(0, numberOfClient, 1):
xorFilenameLength = 0
filenameLength = 0
for j in range(0, 500, 1):
seperateNumber = numberOfClient / (l+1)
randomMatrix = randomfile(fileNumber, numberOfClient, seperateNumber)
randomAskFile = []
tempRange = range(0, fileNumber, 1)
for i in range(0, numberOfClient, 1):
temp = random.sample(tempRange, 1)
randomAskFile.append(temp[0])
xorFilename, filename = findXorfile(fileNumber, numberOfClient, randomMatrix, randomAskFile, seperateNumber)
xorFilenameLength = xorFilenameLength + len(xorFilename)
filenameLength = filenameLength + len(filename)
#print xorFilenameLength,filenameLength
xorFilenameLength = xorFilenameLength / 2 / 500
filenameLength = filenameLength / 500
#print xorFilenameLength,filenameLength
totalLength.append(float(xorFilenameLength + filenameLength)/(fileNumber * seperateNumber))
print totalLength
'''