vendredi 22 février 2019

Python choose random number in specific interval

So I'm making a PyGame that baseball is falling from up, and users in the bottom have to catch the ball. The balls are falling in a random speed, but I'm having hard time getting balls falling in different speed.

For example, my current code for the ball is:

def update(self):
    if self.is_falling:
        """Move the ball down."""
        self.y += random.randint(10, 200) / 100
        self.rect.y = self.y

Here, when I run the program, the ball is falling in different speed but it's barely different. If I change the number to make it to (10, 20000) / 100 then every ball is dropping very fast. What would be the reason? Seems like random number is not so random. Am I using the function wrong?

I want to make each ball to drop in VERY different speed, such as one is very fast, and the other is very slow. And I would want it to be random number so that users can play with many different speed...

I wondered, if there is random function that I can set with a specific interval between generated random numbers? Or should I try a different approach? And if so, how should I do it?

I am very beginner at Python, so if you can explain it easy as possible, that will be much appreciated!




Aucun commentaire:

Enregistrer un commentaire