From 67e37ff31ef2a2e1f62b4e843c7767b883d372effa38991172af95fa8519f13e Mon Sep 17 00:00:00 2001 From: Euiseo Cha Date: Fri, 18 Oct 2024 01:16:10 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B5=AC=ED=98=84=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- draw.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 draw.py diff --git a/draw.py b/draw.py new file mode 100644 index 0000000..12cd672 --- /dev/null +++ b/draw.py @@ -0,0 +1,42 @@ +import time + +def dev_urandom_index(lists: list): + with open('/dev/urandom', 'rb') as urandom: + random_bytes = urandom.read(2) + random_number = int.from_bytes(random_bytes, 'big') + random_index = random_number % len(lists) + return random_index + +def draw_from_list(lists: list, draw_count: int): + draweds = [] + for _ in range(draw_count): + random_index = dev_urandom_index(lists) + drawed = lists.pop(random_index) + draweds.append(drawed) + return draweds + +def color_text(text: str, color_code: str): + start = f"\033[{color_code}m" + reset = "\033[0m" + return f"{start}{text}{reset}" + +def view(num: int, drawed: str): + print(f"\n{num}번째 당첨자를 선정합니다...") + time.sleep(1) + print(".", end="", flush=True) + time.sleep(1) + print(".", end="", flush=True) + time.sleep(1) + print(".\n") + print(f"축하합니다! {num}번째 당첨자는 {color_text(drawed, 36)}님 입니다!") + time.sleep(1.5) + + +if __name__ == "__main__": + draw_count = input("당첨자 수를 입력하세요: ") + lists = input("참가자 리스트를 공백으로 구분하여 입력하세요: ").split() + draweds = draw_from_list(lists, int(draw_count)) + for num, drawed in enumerate(draweds): + view(num + 1, drawed) + + print("\n최종 당첨자: " + color_text(f"{' '.join(draweds)}", 36)) \ No newline at end of file