a python.program for random no.-s without randmodule.
Home
/
Computer Science
/
a python.program for random no.-s without randmodule.
a python.program for random no.-s without randmodule.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
from subprocess import check_output
def rand_num(start, end, n):
cmd = ["shuf", "-i", f"{start}-{end}", "-n", f"{n}"]
out = check_output(cmd, universal_newlines = True)
return list(map(int, out.split())) if n > 1 else int(out)
start, end, n = int(input("start: ")), int(input("end: ")), int(input("n: "))
print(rand_num(start, end, n))
# disclaimer: will only work on Windows Subsystem for Linux, Linux or Mac OS environment.
Answer:
from subprocess import check_output
def rand_num(start, end, n):
cmd = ["shuf", "-i", f"{start}-{end}", "-n", f"{n}"]
out = check_output(cmd, universal_newlines = True)
return list(map(int, out.split())) if n > 1 else int(out)
start, end, n = int(input("start: ")), int(input("end: ")), int(input("n: "))
print(rand_num(start, end, n))
# disclaimer: will only work on Windows Subsystem for Linux, Linux or Mac OS environment.