samedi 15 octobre 2022

Python random gives really bad numbers

Here I have a function to choose "sun of the day" in a chat. But I observed that it works really bad. For example, in a chat of 8 members, one man hadn't been "sun of the day" for 56 days! Can this problem be solved using only python features, not connecting any external services such as random.org API?

def send_sun(id):
    try:
        members = (vk_session.method('messages.getConversationMembers', {'peer_id': 2000000000 + id})['profiles'])
        num_of_members = len(members)
        if num_of_members == 1:
            send(id, "Хотела я выбрать из этой беседы солнышко, а выбирать-то не из кого, вы здесь один...")
        else:
            sun = random.choince(members)['id']
            sun_profile = vk_session.method('users.get', {'user_ids' : sun})[0]
            if(setting_interface.check(id, "send_sun")):
                send(id, "Солнышко сегодняшнего дня - [id" + str(sun_profile['id']) + "|" + sun_profile['first_name'] + " "+ sun_profile ['last_name'] + "]")
            return
    except:
        send(id, "Что-то не то с солнышком. Пожалуйста, проверьте, что у меня есть права администратора, попробуйте выключить эту функцию и включить снова (команды могу напомнить по команде: Ира, что ты умеешь?). Если проблема не исчезнет, сообщите моему создателю, пожалуйста")

I should add that the bot is restarted each day about 1 a.m., and the suns are chosen each day about 12 pm. May be, it influences random.seed()?




Aucun commentaire:

Enregistrer un commentaire