Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import sys
- import random
- def main(argv):
- if len(argv) == 1:
- print 'Usage: python txtfile.py random-seed(int)'
- return 0
- i = 0
- seed = int(argv[1])
- random.seed(seed)
- print 'Ctrl-C to cancel the loop'
- try:
- with file('random_numbers.txt', 'w') as fp:
- while True:
- rnd = random.randint(1, 100)
- message = 'iteration: {ITER}, random number: {RND}\n'.format(ITER=i, RND=rnd)
- fp.write(message)
- time.sleep(3)
- i += 1
- except KeyboardInterrupt:
- print 'Ctrl-C, exit'
- return 0
- if __name__ == '__main__':
- main(sys.argv)
Advertisement
Add Comment
Please, Sign In to add comment