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

related values don't line up, even if seed is reset #2063

Open
cornfeedhobo opened this issue Jun 20, 2024 · 1 comment
Open

related values don't line up, even if seed is reset #2063

cornfeedhobo opened this issue Jun 20, 2024 · 1 comment

Comments

@cornfeedhobo
Copy link

cornfeedhobo commented Jun 20, 2024

When pulling things like country(), it would be useful if the country_code() matched, but it currently doesn't.

Expected behavior

Faker.seed(0)
Faker().country() # "Tanzania"
Faker.seed(0)
Faker().country_code() # "TZ"

Actual behavior

Faker.seed(0)
Faker().country() # "Tanzania"
Faker.seed(0)
Faker().country_code() # "MV"
@kevindaglish
Copy link

kevindaglish commented Jun 26, 2024

Hello cornfeedhobo,

I was able to replicate the issue have above. Looking at how the code generates the values using a random generator method which is referencing the same country data. How ever I would question if using a random generator twice with the same seed would be the right approach. As once you have a known expected value (your generated country), it would make sense to reference the country code from the same country data it has been randomised from. Below is a snippet of code which does this.

from faker.proxy import Faker as f
from faker.providers.date_time import Provider
from faker.generator import Generator
from faker.providers import BaseProvider
g = Generator()
b = BaseProvider(g)
p = Provider(b)

f.seed(0)
c = f().country()
cc = [Country for Country in p.countries if Country.name == c]
for each in cc:
country_code = each.alpha_2_code

I hope this is useful for you.

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

2 participants