Uso de números aleatorios con Python


En Python podemos usar números aleatorios usando el módulo random
import random
print(random.random())
Output:
0.5412534406894142

import random
numeros = 10
ans = []
for i in range(numeros):
    ans.append(random.random())
print(ans)
Output:
[0.4821087938643043, 0.2406183464925573, 0.27587630878244995, 0.2192253697808313, 0.581660300315342, 0.24865823798382347, 0.14378892121595566, 0.7124086060724959, 0.8264810304435963, 0.16371422078033615]
Links
  1. https://docs.python.org/3/library/random.html

No hay comentarios.:

Publicar un comentario