mercredi 9 août 2023

Why is python random module returning smaller numbers than expected?

I am programming a twitch bot, and am trying to use the random module to select a random number for determining whether a move hits or not in a chat game I am making. The problem I am running into is that, despite the fact that I want the function to generate a number between 1 and 100, it will only ever generate numbers below 50, and I have no idea why. Yes, I've ran the code many many times to make sure I'm not just unlucky. I've looked for people with similar problems online, and haven't had any luck. Am I using the module improperly? is there some software on twitch's end interfering? I apologize if this question has been answered somewhere else, but I couldn't find it.

def Execute(data):
    if data.IsChatMessage() == False:
        return
    if data.GetParam(0).lower() == "!roll":
        DiceRoll=random.randint(1,100)
        Parent.SendStreamMessage(str(DiceRoll))

Since I am programming a streamlabs twitch chat bot, there are certain commands that streamlabs has built in, such as getting parameters from twitch chat messages and sending stream messages. The issue is that, when running this function, the bot will always respond with a number less than 50. Does anyone understand why? (As a side note, it also seems to perform exclusively floor division. For example, 13/2 and 13//2 both return 6, perhaps hinting at some error in the streamlabs chatbot software? I am new to this and really don't know tbh. I discovered this while trying to get around the bugged random module by checking for even vs odd instead of for how big the number was, but that also failed due to the weird division)

Edit: as was requested, I have added my code which returned averages of 24, 27, and 26.

def Execute(data):
    avr=0
    if data.IsChatMessage() == False:
        return
    if data.GetParam(0).lower() == "!bive":
        DiceRoll=random.randint(1,100)
        Parent.SendStreamMessage(str(DiceRoll))
        
        for i in range(100):
            avr+=random.randint(1,100)
        avr=avr/100
        Parent.SendStreamMessage(str(avr))



Aucun commentaire:

Enregistrer un commentaire