mardi 23 mars 2021

True random numbers [closed]

so i started creating a snake game an would like to have some fruits popup randomly on the screen, i did it with 1 fruit at a time, using random.randint() but when i try to draw multiple fruits they appear close to each other.

My code is really simple, it's just a function that takes a number and creates a list with coordinates for each iteration of the number.

My only guess is that because random.randint() is a pseudo-random generator, it just grabs the current time in seconds (and maybe some more variables/values) and calculates a number using these values, but since the time doesn't change that much the calculation ends up with coords close to each other.

Is there a way to calculate Truly random numbers (like getting fan noise, background-processes number, etc) in python (3.9) if yes how?

if not, is there a way to generate a lot of values that are not close to each other in a small amount of time?

EDIT:

import random

def generateCoordList(num):
    lst = []
    for i in range(num):
        lst.append( (random.randint(0, 1000), random.randint(0, 800)) )# append a tuple with random X and Y
    return lst

it's just a for-append loop that stores tuples of numbers in a list




Aucun commentaire:

Enregistrer un commentaire