Skip to content

Instantly share code, notes, and snippets.

@lucassmagal
Created November 28, 2012 01:09
Show Gist options
  • Save lucassmagal/4158351 to your computer and use it in GitHub Desktop.
Save lucassmagal/4158351 to your computer and use it in GitHub Desktop.
Salva n numeros ordenados randomicamente em um arquivo
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from random import random, shuffle
TOTAL_NUMBERS = 1000000
def gera_txt(n=TOTAL_NUMBERS):
numbers = range(1, n + 1)
shuffle(numbers, random=random)
with open('output.txt', 'w') as output:
for number in numbers:
output.write('%d\n' % number)
if __name__ == '__main__':
numbers = TOTAL_NUMBERS if len(sys.argv) == 1 else int(sys.argv[1])
print 'Gerando %d numeros ordenados randomicamente...' % numbers
gera_txt(numbers)
print 'Ok, pronto =D Salvo em output.txt'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment