Skip to content

Faker random elements with probability have old example in documentation #35

@Worvast

Description

@Worvast

Actual example:

<14>{{next(date_generator)}} {{ fake.random_element(('ABCDEFGHI01', 'ABCDEFGHI02')) }} firewall.cisco.asa: 2018-03-22T23:56:09.237067-07:00 : %ASA-123456: Teardown dynamic {{ fake.random_element(('TCP', 'UDP', 'ICMP')) }} translation from inside:{{ fake.ipv4() }}/{{ fake.int(1, 65000) }} to outside:{{ fake.ipv4() }}/{{ fake.int(1, 65000) }} duration 0:02:32

Its wrong, the new use of random_element must import OrderedDict from collections, one example can be:

`from devoutils.faker import SyslogFakeGenerator
from collections import OrderedDict

def get_choices():
return ["Failed", "Success", "Totally broken", "404", "500", "What?"]

if name == "main":
with open("orderer_dict.jinja2", 'r') as myfile:
template1 = myfile.read()

custom = {"od": OrderedDict}

f = SyslogFakeGenerator(engine=1, template=template1, simulation=True,
                        probability=100,
                        frequency=(1, 1),
                        providers=custom,
                        verbose=True)
f.start()

`

{%- set re = fake.random_element(elements=od([("a", 0.7), ("b", 0.2), ("c", 0.05), ("d", 0.05)])) -%} nabo {{ re }}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions