as mentioned in the title:
如标题中所述:
I'm trying to loop this so it prints all results line by line :
我试图循环这个,所以它逐行打印所有结果:
k=random.randint(0, 1000)
I'm using batch file to keep printing the random numbers but it is very slow:
我正在使用批处理文件来保持打印随机数,但速度非常慢:
@echo off
cls
:start
k.py
goto start
how can i do this in python ?
我怎么能在python中做到这一点?
1 个解决方案
#1
2
import random
# prints an endless list of random numbers
while True:
num = random.randint(0, 1000)
print(num)
other alternatives:
# print 1000 random numbers
for i in range(1000):
num = random.randint(0, 1000)
print(num)
or
# print the numbers 0..1000 in random order
nums = list(range(1001))
random.shuffle(nums) # shuffle list in-place
for num in nums:
print(num)
#1
2
import random
# prints an endless list of random numbers
while True:
num = random.randint(0, 1000)
print(num)
other alternatives:
# print 1000 random numbers
for i in range(1000):
num = random.randint(0, 1000)
print(num)
or
# print the numbers 0..1000 in random order
nums = list(range(1001))
random.shuffle(nums) # shuffle list in-place
for num in nums:
print(num)