randomize works
This commit is contained in:
parent
ae6fefdc7d
commit
fb3e003073
13
randomize.py
13
randomize.py
@ -1,20 +1,21 @@
|
|||||||
#!/usr/bin/python2
|
#!/usr/bin/python2
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import random
|
import random, time
|
||||||
|
|
||||||
# TODO: вернуться, отладить
|
|
||||||
|
|
||||||
def write_user(username, table_size):
|
def write_user(username, table_size):
|
||||||
|
repeater = False
|
||||||
random_seed = random.choice(range(1, table_size))
|
random_seed = random.choice(range(1, table_size))
|
||||||
tfile = open('table.txt', 'a+r')
|
tfile = open('table.txt', 'r+a')
|
||||||
tabledata = tfile.readlines()
|
tabledata = tfile.readlines()
|
||||||
for line in tabledata:
|
for line in tabledata:
|
||||||
if line.split(' | ')[0] == str(random_seed):
|
if line.split(' | ')[0] == str(random_seed):
|
||||||
# repeat from begin
|
# repeat from begin
|
||||||
|
repeater = True
|
||||||
write_user(username, table_size)
|
write_user(username, table_size)
|
||||||
# if we haven't matching number, write das line
|
# 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):
|
def check_file(username, table_size):
|
||||||
try:
|
try:
|
||||||
@ -22,7 +23,7 @@ def check_file(username, table_size):
|
|||||||
write_user(username, table_size)
|
write_user(username, table_size)
|
||||||
except IOError:
|
except IOError:
|
||||||
tablefile = open('table.txt', 'w')
|
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()
|
tablefile.close()
|
||||||
write_user(username, table_size)
|
write_user(username, table_size)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user