Skip to content

Instantly share code, notes, and snippets.

@nsabine
Last active December 17, 2015 01:19

Revisions

  1. nsabine revised this gist Jul 8, 2013. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions random_generator.py
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,14 @@
    import random

    def random_int(num = 1, min = 1, max = 100):
    def random_int(num: int = 1, min: int = 1, max: int = 100) -> [int]:
    """Return a list of random integers."""
    ints = []
    for i in xrange(num):
    ints.append(random.randint(min,max))
    return ints

    def random_word(num = 1):
    def random_word(num: int = 1) -> [str]:
    """Return a list of random words."""
    with open('/usr/share/dict/words', 'rt') as f:
    words = f.readlines()
    allwords = [ w.rstrip() for w in words ]
    @@ -17,4 +19,4 @@ def random_word(num = 1):

    if __name__ == '__main__':
    print("Random Words: " + ','.join(random_word(5)))
    print("Random Integers: " + ','.join([str(i) for i in random_int(5)]))
    print("Random Integers: " + ','.join([str(i) for i in random_int(5)]))
  2. nsabine renamed this gist May 6, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. nsabine created this gist May 6, 2013.
    20 changes: 20 additions & 0 deletions random.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    import random

    def random_int(num = 1, min = 1, max = 100):
    ints = []
    for i in xrange(num):
    ints.append(random.randint(min,max))
    return ints

    def random_word(num = 1):
    with open('/usr/share/dict/words', 'rt') as f:
    words = f.readlines()
    allwords = [ w.rstrip() for w in words ]
    words = []
    for w in random.sample(allwords, num):
    words.append(w)
    return words

    if __name__ == '__main__':
    print("Random Words: " + ','.join(random_word(5)))
    print("Random Integers: " + ','.join([str(i) for i in random_int(5)]))