Esempio n. 1
0
def test_not_really_random():
    # If your xkcd-style password comes out like this, maybe you shouldn't
    # use it
    assert random_words(nwords=4, lang='en', bits_per_word=0) == 'the the the the'

    # This not only tests random_ascii_words, it makes sure we didn't end
    # up with 'eos' as a very common Japanese word
    assert random_ascii_words(nwords=4, lang='ja', bits_per_word=0) == '00 00 00 00'
Esempio n. 2
0
def test_not_really_random():
    # If your xkcd-style password comes out like this, maybe you shouldn't
    # use it
    eq_(random_words(nwords=4, lang="en", bits_per_word=0), "the the the the")

    # This not only tests random_ascii_words, it makes sure we didn't end
    # up with 'eos' as a very common Japanese word
    eq_(random_ascii_words(nwords=4, lang="ja", bits_per_word=0), "rt rt rt rt")
Esempio n. 3
0
def test_not_really_random():
    # If your xkcd-style password comes out like this, maybe you shouldn't
    # use it
    eq_(random_words(nwords=4, lang='en', bits_per_word=0), 'the the the the')

    # This not only tests random_ascii_words, it makes sure we didn't end
    # up with 'eos' as a very common Japanese word
    eq_(random_ascii_words(nwords=4, lang='ja', bits_per_word=0), '1 1 1 1')
Esempio n. 4
0
def get_word_pair(language):
    lang = lang_dict[language]
    try:
        lang_word = wordfreq.random_words(lang, nwords=1)
        while lang_word is None:
            lang_word = wordfreq.random_words(lang, nwords=1)
        eng_word = translator.translate(lang_word, src=lang, dest='en').text

        # Recursion happening here
        if len(lang_word) > 10 or len(eng_word) > 10 or (len(lang_word) == 1 and len(eng_word) == 1) \
            or (language != "English" and lang_word == eng_word) or lang_word[0].isupper():
            lang_word, eng_word = get_word_pair(language)
    except:
        with open("words.pkl", "rb") as f:
            dictionary = pickle.load(f)
        lang_word, eng_word = random.choice(dictionary[language])

    return lang_word, eng_word
Esempio n. 5
0
def create_local_file(num):
    save_dict = {}
    for language, lang in lang_dict.items():
        save_dict[language] = []
        for j in range(num):
            lang_word = wordfreq.random_words(lang, nwords=1)
            while lang_word is None:
                lang_word = wordfreq.random_words(lang, nwords=1)
            eng_word = translator.translate(lang_word, src=lang,
                                            dest='en').text

            # Recursion happening here
            if len(lang_word) > 10 or len(eng_word) > 10 or (len(lang_word) == 1 and len(eng_word) == 1) \
                or (language != "English" and lang_word == eng_word) or lang_word[0].isupper():
                lang_word, eng_word = get_word_pair(language)

            save_dict[language].append((lang_word, eng_word))
    with open("words.pkl", "wb") as f:
        pickle.dump(save_dict, f)
Esempio n. 6
0
import random
from wordfreq import random_words

BAD_COMMON_WORDS = [
    'entertainment', 'internet', 'advertising', 'retail', 'insurance',
    'software', 'clothing', 'music', 'film', 'restaurants', 'social',
    'industry', 'security', 'manufacturing', 'engineering', 'transport',
    'construction', 'mining', 'defence'
]
COMMON_WORDS = list(
    set(random_words(lang='en', wordlist='best', nwords=100000).split(' ')))
for bw in BAD_COMMON_WORDS:
    COMMON_WORDS.remove(bw)
from names_dataset import NameDataset

d = NameDataset()
NAMES = list(d.first_names)
SURNAMES = list(d.last_names)
ALPHABET = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
    'p', 'q', 'r', 's', 't', 'u', 'v', 'x', 'y', 'z', ' ', ' ', ' ', ' '
]


def get_placeholder(size):
    return ''.join(random.choices(ALPHABET, k=size))


def get_bool_rand():
    return random.choice([True, False])