1
Fork 0

randomize works

master
Valdos Sine 2013-08-26 21:12:19 +04:00
parent ae6fefdc7d
commit fb3e003073
1 changed files with 7 additions and 6 deletions

View File

@ -1,20 +1,21 @@
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import random
# TODO: вернуться, отладить
import random, time
def write_user(username, table_size):
repeater = False
random_seed = random.choice(range(1, table_size))
tfile = open('table.txt', 'a+r')
tfile = open('table.txt', 'r+a')
tabledata = tfile.readlines()
for line in tabledata:
if line.split(' | ')[0] == str(random_seed):
# repeat from begin
repeater = True
write_user(username, table_size)
# if we haven't matching number, write das line
tfile.write("%i | %s\n" % (random_seed, username))
if repeater == False:
tfile.write("%i | %s\n" % (random_seed, username))
def check_file(username, table_size):
try:
@ -22,7 +23,7 @@ def check_file(username, table_size):
write_user(username, table_size)
except IOError:
tablefile = open('table.txt', 'w')
tablefile.write("Рандомизатор: составление таблицы методом случайных чисел.\nРазмер таблицы: %s\n\n========\n\n" % table_size)
tablefile.write("Жеребьевка участников LORChess.\nРазмер таблицы участников: %s.\nДанный файл является неизменяемым и создаваемым один раз.\nUNIX timestamp: %i\n========\n\n" % (table_size - 1, int(time.time())))
tablefile.close()
write_user(username, table_size)