49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
"""
|
|
Random Number Generator
|
|
|
|
by BBaoVanC
|
|
|
|
Generates a list of random numbers based on how many you want
|
|
"""
|
|
import random
|
|
|
|
DO_DEBUG = False
|
|
|
|
|
|
def generate(count, digits, debug):
|
|
numbers = list() # create a new blank list for storing our numbers
|
|
count = int(count)
|
|
digits = int(digits)
|
|
debug = bool(debug)
|
|
n = 0
|
|
while n < count:
|
|
maxnum = "9" * digits
|
|
maxnum_int = int(maxnum)
|
|
number = random.randint(0, maxnum_int)
|
|
if debug:
|
|
print("Generated number: " + str(number))
|
|
numbers.append(number) # add a random number from 0 to 999 to the list
|
|
n = n + 1 # increment our counter
|
|
return numbers # return our list of numbers
|
|
|
|
|
|
if __name__ == '__main__':
|
|
amount = input("Amount: ")
|
|
length = input("Length: ")
|
|
nums = generate(int(amount), int(length), DO_DEBUG)
|
|
|
|
f = open("nums.txt", "w+")
|
|
nums2 = list()
|
|
for item in nums:
|
|
item = str(item) + "\n" # add newline character to each item in the nums2 list...
|
|
nums2.append(item) # ...
|
|
nums2[-1] = nums2[-1].strip() # remove newline character from last item in list
|
|
for item in nums2:
|
|
if DO_DEBUG:
|
|
print("Writing number: " + item)
|
|
|
|
f.write(item) # write each number to the file
|
|
if DO_DEBUG:
|
|
print("Closing file")
|
|
f.close()
|