python中随机产生50个小数
时间: 2024-02-01 21:15:29 浏览: 58
Python random 生成随机数
可以使用Python内置的random模块来生成随机小数。
下面是一个示例代码,可以生成50个在0到1之间的小数:
```python
import random
# 生成50个小数
random_numbers = [random.random() for _ in range(50)]
print(random_numbers)
```
输出结果类似于:
```
[0.8142391804018348, 0.767383170081957, 0.7542150627357527, 0.5547946026488676, 0.06743587453236684, 0.7022048117927995, 0.05311668438150427, 0.21298027212054814, 0.20991996426447766, 0.2173007897717876, 0.0653652657099492, 0.1621250895464739, 0.9381703306772327, 0.2015460872996266, 0.6529385571997141, 0.9813633699248914, 0.03680998577275689, 0.8318456616561665, 0.8896409154216706, 0.8444250414811583, 0.6702022071431704, 0.18368580845726472, 0.9322282679186154, 0.7609614924898081, 0.18441116066442267, 0.2784060581795306, 0.003747610333954459, 0.4401216357347226, 0.2879255698878188, 0.7202677494805968, 0.8411537710949008, 0.8803751423403415, 0.5573324444381526, 0.5755183986689365, 0.15154534639712317, 0.7908614293580519, 0.1554599828415871, 0.9809765910048906, 0.34101150438431335, 0.3147428693476971, 0.4812460241106774, 0.8969180721218393, 0.6519941889727556, 0.449617658465978, 0.6288115085687369, 0.3104103176358716, 0.9054919520599927, 0.6229432596381013, 0.7901216965355233, 0.8113300758802167]
```
阅读全文