<commit_before>"""
Predict RNG

Usage:
  predict_rng msvc (rand|rand_r) <count> (--seed=<seed> | <output>...)
  predict_rng glibc (rand|random|rand_r) <count> (--seed=<seed> | <output>...)
  predict_rng php (linux|windows) rand <count> (--seed=<seed> | <output>...)
  predict_rng lcg <multiplier> <increment> <modulus> <bitshift> <count> (--seed=<seed> | <output>...)
"""

from docopt import docopt
from predrng import lcg, glibc, php
from predrng.glibc import random, rand_r
from predrng.php import rand
from itertools import islice


def print_from_gen(generator, count):
    for v in islice(generator, 0, count):
        print(v)


def handle_msvc(args, count, outputs):
    if args["rand"] or args["rand_r"]:
        if args["--seed"]:
            seed = int(args["--seed"])
            print_from_gen(lcg.generate_from_seed(seed), count)
        else:
            print_from_gen(lcg.generate_from_outputs(outputs), count)


def handle_lcg(args, count, outputs):
    a = int(args["<multiplier>"])
    c = int(args["<increment>"])
    m = int(args["<modulus>"])
    bitshift = int(args["<bitshift>"])
    if args["--seed"]:
        seed = int(args["--seed"])
        print_from_gen(lcg.generate_from_seed(seed, a, c, m, bitshift), count)
    else:
        print_from_gen(lcg.generate_from_outputs(outputs, a, c, m, bitshift), count)


def handle_glibc(args, count, outputs):
    if args["rand"] or args["random"]:
        if args["--seed"]:
            seed = int(args["--seed"])
            print_from_gen(glibc.random.generate_from_seed(seed), count)
        else:
            print_from_gen(glibc.random.generate_from_outputs(outputs), count)
    elif args["rand_r"]:
        if args["--seed"]:
            seed = int(args["--seed"])
            print_from_gen(glibc.rand_r.generate_from_seed(seed), count)
        else:
            print_from_gen(glibc.rand_r.generate_from_outputs(outputs), count)


def handle_php(args, count, outputs):
    if args["windows"]:
        platform = "windows"
    elif args["linux"]:
        platform = "linux"

    if args["rand"]:
        if args["--seed"]:
            seed = int(args["--seed"])
            print_from_gen(php.rand.generate_from_seed(seed, platform), count)
        else:
            print_from_gen(php.rand.generate_from_outputs(outputs, platform), count)


def main():
    args = docopt(__doc__)

    outputs = None
    if args["<output>"]:
        outputs = [int(output) for output in args["<output>"]]

    count = int(args["<count>"])
    if args["msvc"]:
        handle_msvc(args, count, outputs)
    elif args["lcg"]:
        handle_lcg(args, count, outputs)
    elif args["glibc"]:
        handle_glibc(args, count, outputs)
    elif args["php"]:
        handle_php(args, count, outputs)

if __name__ == "__main__":
    main()
<commit_msg>Better docs<commit_after>#!/usr/bin/env python
"""
Usage:
  predict_rng msvc  (rand|rand_r) <count> <output>...
  predict_rng msvc  (rand|rand_r) <count> --seed=<seed>
  predict_rng glibc (rand|random|rand_r) <count> <output>...
  predict_rng glibc (rand|random|rand_r) <count> --seed=<seed>
  predict_rng php   (linux|windows) rand <count> <output>...
  predict_rng php   (linux|windows) rand <count> --seed=<seed>
  predict_rng lcg <multiplier> <increment> <modulus> <bitshift> <count> <output>...
  predict_rng lcg <multiplier> <increment> <modulus> <bitshift> <count> --seed=<seed>

Description:
  Given OUTPUTs from a random number generator (glibc's rand_r, PHP rand, etc),
  predict_rng predicts the next COUNT outputs. Alternately, predict_rng can
  be passed the SEED, which will be used to produce the first COUNT outputs
  that would be returned from the random number generator.
"""

from docopt import docopt
from predrng import lcg, glibc, php
from predrng.glibc import random, rand_r
from predrng.php import rand
from itertools import islice


def print_from_gen(generator, count):
    for v in islice(generator, 0, count):
        print(v)


def handle_msvc(args, count, outputs, seed):
    if args["rand"] or args["rand_r"]:
        if seed:
            print_from_gen(lcg.generate_from_seed(seed), count)
        else:
            print_from_gen(lcg.generate_from_outputs(outputs), count)


def handle_lcg(args, count, outputs, seed):
    a = int(args["<multiplier>"])
    c = int(args["<increment>"])
    m = int(args["<modulus>"])
    bitshift = int(args["<bitshift>"])
    if seed:
        print_from_gen(lcg.generate_from_seed(seed, a, c, m, bitshift), count)
    else:
        print_from_gen(lcg.generate_from_outputs(outputs, a, c, m, bitshift), count)


def handle_glibc(args, count, outputs, seed):
    if args["rand"] or args["random"]:
        if seed:
            print_from_gen(glibc.random.generate_from_seed(seed), count)
        else:
            print_from_gen(glibc.random.generate_from_outputs(outputs), count)
    elif args["rand_r"]:
        if seed:
            print_from_gen(glibc.rand_r.generate_from_seed(seed), count)
        else:
            print_from_gen(glibc.rand_r.generate_from_outputs(outputs), count)


def handle_php(args, count, outputs, seed):
    if args["windows"]:
        platform = "windows"
    elif args["linux"]:
        platform = "linux"

    if args["rand"]:
        if seed:
            print_from_gen(php.rand.generate_from_seed(seed, platform), count)
        else:
            print_from_gen(php.rand.generate_from_outputs(outputs, platform), count)


def main():
    args = docopt(__doc__)

    outputs = None
    if args["<output>"]:
        outputs = [int(output) for output in args["<output>"]]

    seed = None
    if args["--seed"]:
        seed = int(args["--seed"])

    count = int(args["<count>"])
    if args["msvc"]:
        handle_msvc(args, count, outputs, seed)
    elif args["lcg"]:
        handle_lcg(args, count, outputs, seed)
    elif args["glibc"]:
        handle_glibc(args, count, outputs, seed)
    elif args["php"]:
        handle_php(args, count, outputs, seed)

if __name__ == "__main__":
    main()

{'fraction_non_alphanumeric': 0.14388009991673606, 'fraction_numerical': 0.00033305578684429644, 'mean_word_length': 3.2236286919831225, 'pattern_counts': {'":': 2, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7099112', 'n_tokens_mistral': 2078, 'n_tokens_neox': 2049, 'n_words': 477}