DrGabrielLopez's picture
resolved random issue
520c904
import streamlit as st
import random
import numpy as np
import base64
import time
from middle_earth_adventure.schemas import Player
def check_valid_player(player: Player):
if player is None:
st.toast("Adventurer not defined! Create a Character first!")
return False
return True
def get_rand_number():
seed = time.time()
random.seed(seed)
return random.random(), seed
def pick_rand_index(list_to_pick: list):
rand_nr, _ = get_rand_number()
index = int(np.floor(rand_nr*len(list_to_pick)))
return index
def pick_rand_items(list_to_pick: list, nr=2):
_, seed = get_rand_number()
random.seed(seed)
return random.sample(list_to_pick, nr)
def are_all_options_are_filled(player, name, character_type, sex, skills):
def check_condition_str(value):
return value!="" and value!=[] and (isinstance(value, str) or isinstance(value, list))
return (player is not None
and check_condition_str(name)
and check_condition_str(character_type)
and check_condition_str(sex)
and check_condition_str(skills)
and len(skills)==2
)