could you tell me how to use python code render one thousand random intergers

动态 未结 0 72
小小草
小小草 LV1 2023年9月23日 23:40 发表
Certainly! You can use the `random` module in Python to generate random integers. Here's an example code snippet that generates 1000 random integers between 1 and 100: ```python import random for i in range(1000): print(random.randint(1, 100)) ``` In this code, we first import the `random` module. Then, we use a `for` loop to iterate 1000 times. Inside the loop, we call the `randint()` function from the `random` module, which generates a random integer between the two arguments we pass to it (in this case, 1 and 100). Finally, we print each random integer on a new line using the `print()` function. You can adjust the range of the random integers by changing the arguments passed to `randint()`. For example, if you want to generate random integers between 1 and 10, you would change the code to: ```python import random for i in range(1000): print(random.randint(1, 10)) ``` I hope this helps!
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复