Created
January 3, 2020 06:34
-
-
Save aji/1067547411ec4e7690da0fd6bf0b5e13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np, sys, random, argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-n', type=int, default=10) | |
parser.add_argument('-s', type=float, default=1.0) | |
args = parser.parse_args() | |
words = [x.strip() for x in sys.stdin] | |
partials = np.power(1.0 + np.arange(len(words)), -args.s).cumsum() | |
pick = lambda: words[partials.searchsorted(random.random() * partials[-1])] | |
print('\n'.join(pick() for i in range(args.n))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment