2 # Display Latin famous phrases in the terminal
10 # Use system random if available, otherwise, use Python's
11 def _random_int(start, end):
13 r = random.SystemRandom()
17 return r.randint(start, end)
19 # Create list of phrases from phrase file
20 def _read_phrases(phrase_file):
21 f = open(phrase_file, 'r')
24 lines = [line.rstrip() for line in contents.split('\n')]
25 delim = re.compile(r'^%$')
29 def save_if_nonempty(buf):
30 phrase = '\n'.join(buf)
32 phrases.append(phrase)
47 # Return a random phrase from the phrases list
48 def get_random_phrase(phrase_file):
49 phrases = list(_read_phrases(phrase_file))
50 randomRecord = _random_int(0, len(phrases) - 1)
51 randphrase = phrases[randomRecord]
52 return randphrase.partition('\n')[0]
56 print(get_random_phrase("/usr/share/phrases/phrases"))