Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Worvast opened this issue Apr 27, 2021 · 0 comments
Open

Comments

@Worvast
Copy link
Member

Worvast commented Apr 27, 2021

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 }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant