Example #1
0
    def draw_parameter(self, random):
        alphabet_size = 1 + dist.geometric(random, 0.1)
        alphabet = []
        buckets = 10
        ascii_chance = random.randint(1, buckets)
        if ascii_chance < buckets:
            space_chance = random.randint(1, buckets - ascii_chance)
        else:
            space_chance = 0
        while len(alphabet) < alphabet_size:
            choice = random.randint(1, buckets)
            if choice <= ascii_chance:
                codepoint = dist.geometric(random, 1.0 / 127)
            elif choice <= ascii_chance + space_chance:
                while True:
                    i = dist.geometric(random, 2 / len(_spaces))
                    if i < len(_spaces):
                        codepoint = _spaces[i]
                        break
            else:
                codepoint = random.randint(0, sys.maxunicode)

            char = hunichr(codepoint)
            if self.is_good(char):
                alphabet.append(char)
        if u'\n' not in alphabet and not random.randint(0, 10):
            alphabet.append(u'\n')
        return tuple(alphabet)
Example #2
0
    def draw_parameter(self, random):
        alphabet_size = 1 + dist.geometric(random, 0.1)
        alphabet = []
        buckets = 10
        ascii_chance = random.randint(1, buckets)
        if ascii_chance < buckets:
            space_chance = random.randint(1, buckets - ascii_chance)
        else:
            space_chance = 0
        while len(alphabet) < alphabet_size:
            choice = random.randint(1, buckets)
            if choice <= ascii_chance:
                codepoint = dist.geometric(random, 1.0 / 127)
            elif choice <= ascii_chance + space_chance:
                while True:
                    i = dist.geometric(random, 2 / len(_spaces))
                    if i < len(_spaces):
                        codepoint = _spaces[i]
                        break
            else:
                codepoint = random.randint(0, sys.maxunicode)

            char = hunichr(codepoint)
            if self.is_good(char):
                alphabet.append(char)
        if u'\n' not in alphabet and not random.randint(0, 10):
            alphabet.append(u'\n')
        return tuple(alphabet)
Example #3
0
    def produce_parameter(self, random):
        alphabet_size = 1 + dist.geometric(random, 0.1)
        alphabet = []
        while len(alphabet) < alphabet_size:
            if random.randint(0, 10):
                codepoint = random.randint(0, sys.maxunicode)
            else:
                codepoint = dist.geometric(random, 1.0 / 127)

            char = hunichr(codepoint)
            if unicodedata.category(char) != 'Cs':
                alphabet.append(char)
        return tuple(alphabet)
Example #4
0
    def produce_parameter(self, random):
        alphabet_size = 1 + dist.geometric(random, 0.1)
        alphabet = []
        while len(alphabet) < alphabet_size:
            if random.randint(0, 10):
                codepoint = random.randint(0, sys.maxunicode)
            else:
                codepoint = dist.geometric(random, 1.0 / 127)

            char = hunichr(codepoint)
            if unicodedata.category(char) != 'Cs':
                alphabet.append(char)
        return tuple(alphabet)
Example #5
0
    def draw_parameter(self, random):
        alphabet_size = 1 + dist.geometric(random, 0.1)
        alphabet = []
        while len(alphabet) < alphabet_size:
            if random.randint(0, 10):
                codepoint = random.randint(0, sys.maxunicode)
            else:
                codepoint = dist.geometric(random, 1.0 / 127)

            char = hunichr(codepoint)
            if self.is_good(char):
                alphabet.append(char)
        return tuple(alphabet)
Example #6
0
    def draw_parameter(self, random):
        alphabet_size = 1 + dist.geometric(random, 0.1)
        alphabet = []
        while len(alphabet) < alphabet_size:
            if random.randint(0, 10):
                codepoint = random.randint(0, sys.maxunicode)
            else:
                codepoint = dist.geometric(random, 1.0 / 127)

            char = hunichr(codepoint)
            if self.is_good(char):
                alphabet.append(char)
        return tuple(alphabet)
Example #7
0
 def draw_parameter(self, random):
     locales = dist.non_empty_subset(random, self.locales)
     n = 1 + geometric(random, 0.1)
     return [
         self.gen_example(random, locales)
         for _ in hrange(n)
     ]
Example #8
0
 def draw_parameter(self, random):
     locales = dist.non_empty_subset(random, self.locales)
     n = 1 + geometric(random, 0.1)
     return [
         self.gen_example(random, locales)
         for _ in hrange(n)
     ]
Example #9
0
 def draw_parameter(self, random):
     if self.user_parameter is not None:
         up = random.getrandbits(64)
     else:
         up = 0
     n_distinct_templates = dist.geometric(random, random.random())
     template_choices = tuple(random.getrandbits(64) for _ in hrange(n_distinct_templates))
     return (up, template_choices)
Example #10
0
 def draw_template(self, random, pv):
     if self.element_strategy is None:
         return ()
     length = clamp(self.min_size, dist.geometric(random, 1.0 / (1 + pv.average_length)), self.max_size)
     result = []
     for _ in hrange(length):
         result.append(self.element_strategy.draw_template(random, pv.child_parameter))
     return tuple(result)
Example #11
0
 def draw_parameter(self, random):
     if self.user_parameter is not None:
         up = random.getrandbits(64)
     else:
         up = 0
     n_distinct_templates = dist.geometric(random, random.random())
     template_choices = tuple(
         random.getrandbits(64) for _ in hrange(n_distinct_templates))
     return (up, template_choices)
Example #12
0
 def produce_template(self, context, pv):
     if self.element_strategy is None:
         return frozenset()
     result = set()
     length = dist.geometric(context.random, pv.stopping_chance)
     for _ in hrange(length):
         result.add(
             self.element_strategy.produce_template(context,
                                                    pv.child_parameter))
     return frozenset(result)
Example #13
0
 def produce_template(self, context, pv):
     if self.element_strategy is None:
         return ()
     length = dist.geometric(context.random, 1.0 / (1 + pv.average_length))
     result = []
     for _ in hrange(length):
         result.append(
             self.element_strategy.draw_template(
                 context, pv.child_parameter))
     return tuple(result)
Example #14
0
 def produce_template(self, context, pv):
     if self.element_strategy is None:
         return ()
     length = dist.geometric(context.random, 1.0 / (1 + pv.average_length))
     result = []
     for _ in hrange(length):
         result.append(
             self.element_strategy.draw_template(
                 context, pv.child_parameter))
     return tuple(result)
Example #15
0
 def produce_template(self, context, pv):
     if self.element_strategy is None:
         return frozenset()
     result = set()
     length = dist.geometric(context.random, pv.stopping_chance)
     for _ in hrange(length):
         result.add(self.element_strategy.produce_template(
             context, pv.child_parameter
         ))
     return frozenset(result)
Example #16
0
 def draw_template(self, random, pv):
     n_children = geometric(random, pv.branch_factor)
     if not n_children:
         return Leaf(
             self.leaf_strategy.draw_template(random, pv.leaf_parameter))
     else:
         children = tuple(
             (self.branch_key_strategy.draw_template(
                 random, pv.branch_key_parameter),
              self.draw_template(random, pv)) for _ in hrange(n_children))
         label = self.branch_label_strategy.draw_template(
             random, pv.branch_label_parameter)
         return Branch(label=label, keyed_children=children)
Example #17
0
 def draw_template(self, random, pv):
     if self.element_strategy is None:
         return ()
     length = clamp(
         self.min_size,
         dist.geometric(random, 1.0 / (1 + pv.average_length)),
         self.max_size,
     )
     result = []
     for _ in hrange(length):
         result.append(
             self.element_strategy.draw_template(random,
                                                 pv.child_parameter))
     return tuple(result)
Example #18
0
    def draw_template(self, random, parameter):
        if self.min_size == self.max_size:
            size = self.min_size
        elif self.max_size < float("inf"):
            lower = math.floor(self.average_size)
            upper = math.ceil(self.average_size)
            mid_of_lower = (lower + self.min_size) / 2
            mid_of_upper = (upper + self.max_size) / 2
            p = (mid_of_upper - self.average_size) / (mid_of_upper - mid_of_lower)
            if random.random() <= p:
                size = random.randint(self.min_size, lower)
            else:
                size = random.randint(upper, self.max_size)
        else:
            size = self.min_size + dist.geometric(random, 1.0 / (self.average_size - self.min_size + 1))

        return UniqueListTemplate(size, parameter[0], parameter[1], random.getrandbits(64), None)
Example #19
0
 def draw_template(self, random, pv):
     n_children = geometric(random, pv.branch_factor)
     if not n_children:
         return Leaf(self.leaf_strategy.draw_template(
             random, pv.leaf_parameter
         ))
     else:
         children = tuple(
             (self.branch_key_strategy.draw_template(
                 random, pv.branch_key_parameter),
              self.draw_template(random, pv))
             for _ in hrange(n_children))
         label = self.branch_label_strategy.draw_template(
             random, pv.branch_label_parameter
         )
         return Branch(
             label=label, keyed_children=children
         )
Example #20
0
    def draw_template(self, random, parameter):
        if self.min_size == self.max_size:
            size = self.min_size
        elif self.max_size < float('inf'):
            lower = math.floor(self.average_size)
            upper = math.ceil(self.average_size)
            mid_of_lower = (lower + self.min_size) / 2
            mid_of_upper = (upper + self.max_size) / 2
            p = (mid_of_upper - self.average_size) / (mid_of_upper -
                                                      mid_of_lower)
            if random.random() <= p:
                size = random.randint(self.min_size, lower)
            else:
                size = random.randint(upper, self.max_size)
        else:
            size = self.min_size + dist.geometric(
                random, 1.0 / (self.average_size - self.min_size + 1))

        return UniqueListTemplate(size, parameter[0], parameter[1],
                                  random.getrandbits(64), None)
Example #21
0
    def draw_parameter(self, random):
        ascii_categories = charstree.categories(self.ascii_tree)
        unicode_categories = charstree.categories(self.unicode_tree)
        spaces_categories = charstree.categories(self.spaces_tree)

        alphabet_size = 1 + dist.geometric(random, 0.1)
        alphabet = []
        buckets = 10
        ascii_chance = random.randint(1, buckets)

        if spaces_categories and ascii_chance < buckets:
            space_chance = random.randint(1, buckets - ascii_chance)
        else:
            space_chance = 0

        while len(alphabet) < alphabet_size:
            choice = random.randint(1, buckets)

            if ascii_categories and choice <= ascii_chance:
                category = random.choice(ascii_categories)
                tree = self.ascii_tree
            elif spaces_categories and choice <= ascii_chance + space_chance:
                category = random.choice(spaces_categories)
                tree = self.spaces_tree
            else:
                category = random.choice(unicode_categories)
                tree = self.unicode_tree

            codepoint = charstree.random_codepoint(tree, category, random)
            alphabet.append(hunichr(codepoint))

        if u'\n' not in alphabet and not random.randint(0, 6):
            if self.is_good(u'\n'):
                alphabet.append(u'\n')

        return tuple(alphabet)
    def draw_parameter(self, random):
        ascii_categories = charstree.categories(self.ascii_tree)
        unicode_categories = charstree.categories(self.unicode_tree)
        spaces_categories = charstree.categories(self.spaces_tree)

        alphabet_size = 1 + dist.geometric(random, 0.1)
        alphabet = []
        buckets = 10
        ascii_chance = random.randint(1, buckets)

        if spaces_categories and ascii_chance < buckets:
            space_chance = random.randint(1, buckets - ascii_chance)
        else:
            space_chance = 0

        while len(alphabet) < alphabet_size:
            choice = random.randint(1, buckets)

            if ascii_categories and choice <= ascii_chance:
                category = random.choice(ascii_categories)
                tree = self.ascii_tree
            elif spaces_categories and choice <= ascii_chance + space_chance:
                category = random.choice(spaces_categories)
                tree = self.spaces_tree
            else:
                category = random.choice(unicode_categories)
                tree = self.unicode_tree

            codepoint = charstree.random_codepoint(tree, category, random)
            alphabet.append(hunichr(codepoint))

        if u'\n' not in alphabet and not random.randint(0, 6):
            if self.is_good(u'\n'):
                alphabet.append(u'\n')

        return tuple(alphabet)
Example #23
0
 def draw_template(self, random, parameter):
     return dist.geometric(random, parameter)
Example #24
0
 def produce_template(self, context, parameter):
     return self.lower_bound + dist.geometric(context.random, parameter)
Example #25
0
 def produce_parameter(self, random):
     n = 1 + dist.geometric(random, 0.01)
     results = []
     for _ in hrange(n):
         results.append(random.randint(self.start, self.end))
     return results
Example #26
0
 def produce_template(self, context, parameter):
     value = dist.geometric(context.random, parameter.p)
     if dist.biased_coin(context.random, parameter.negative_probability):
         value = -value
     return value
Example #27
0
 def produce_template(self, context, parameter):
     return self.lower_bound + dist.geometric(context.random, parameter)
Example #28
0
 def draw_template(self, random, parameter):
     return self.lower_bound + dist.geometric(random, parameter)
Example #29
0
 def draw_template(self, random, parameter):
     value = dist.geometric(random, parameter.p)
     if dist.biased_coin(random, parameter.negative_probability):
         value = -value
     return value
Example #30
0
 def draw_template(self, random, parameter):
     return self.lower_bound + dist.geometric(random, parameter)
Example #31
0
 def draw_parameter(self, random):
     n = 1 + dist.geometric(random, 0.01)
     results = []
     for _ in hrange(n):
         results.append(random.randint(self.start, self.end))
     return results
Example #32
0
 def draw_template(self, random, parameter):
     return dist.geometric(random, parameter)
Example #33
0
 def produce_template(self, context, parameter):
     value = dist.geometric(context.random, parameter.p)
     if dist.biased_coin(context.random, parameter.negative_probability):
         value = -value
     return value
Example #34
0
 def draw_template(self, random, parameter):
     value = dist.geometric(random, parameter.p)
     if dist.biased_coin(random, parameter.negative_probability):
         value = -value
     return value