Repository: joke2k/faker

Issue:
Faker returns one value when using multiple locales
* Faker version: 13.11
* OS: Mac OS Monterey
Computer: MacBook Pro (14-inch, 2021)

Brief summary of the issue goes here.
If using multiple locales, faker only makes one choice. This only happens when you select multiple locales

### Steps to reproduce

```
from faker import Faker

fake = Faker(["en_GB", "fr_FR", "en_IN"])
Faker.seed(0)
for _ in range(5):
    print(fake.date_time_this_year())

```

### Expected behavior
returns
```
2022-03-16 19:22:23
2022-03-23 16:00:20
2022-01-08 20:40:15
2022-02-20 06:38:22
2022-04-10 06:42:46
```

### Actual behavior
returns
```
2022-03-23 16:00:20
2022-03-23 16:00:20
2022-03-23 16:00:20
2022-03-23 16:00:20
2022-03-23 16:00:20

```


Discussion:
Same problem here,
Faker version: 13.13
OS: Ubuntu 20.04

![image](https://user-images.githubusercontent.com/8634821/174465078-1dbcff6d-e653-4c26-bea5-a764ad712475.png)

```
Faker.seed(1111)
def init():
    fake = Faker(["it_IT", "en_GB", "zh_CN", "en_US", "ja_JP"])
    fake.unique.clear()
    a = [fake.name() for a in range(1000)]
    print(a)
```
It happens both in Pycharm and in bash.
Although when I step into the code, (step into all the functions), it will produce a different result. Then in the same debug session, if I don't step into faker, it will produce the same name again.

This issue is stale because it has been open for 30 days with no activity.
Same for version 14.2.0, here's a script I wrote that shows the behavior too:

```python
from faker import Faker

locales = ['en_US', 'ja_JP']

Faker.seed(0)

# Faker with no locales
f = Faker()
for _ in range(10):
    print(f.name())

print("\nAdding Locales \n")

# Faker with locales
f = Faker(locales)
for _ in range(10):
    print(f.name())
```
It looks like the problem occurs when the seed is set to a specific value. 

```python
from faker import Faker
Faker.seed()
fake = Faker(['it_IT', 'en_US', 'ja_JP'])
for _ in range(10):
    print(fake.name())
```

results in this output:
```
山田 治
Giampaolo Martucci-Norbiato
Gabriella Foletti
Gelsomina Montalti
Shawn Ford
岡田 拓真
吉田 直人
Gloria Morricone
Alessandra Montanariello
中川 直子
```

However, setting the seed to a specific value produces the issue:
```python
from faker import Faker
Faker.seed(0)
fake = Faker(['it_IT', 'en_US', 'ja_JP'])
for _ in range(10):
    print(fake.name())
```

results in 
```
Jennifer Green
Jennifer Green
Jennifer Green
Jennifer Green
Jennifer Green
Jennifer Green
Jennifer Green
Jennifer Green
Jennifer Green
Jennifer Green
```
Same here:

```
>>> from faker import Faker
>>> Faker.seed(42)
>>> fake = Faker(['en_US', 'cs_CZ'])
>>> fake.name()
'Donald Walker'
>>> fake.name()
'Donald Walker'
>>> fake.name()
'Donald Walker'
```

The problem occurs when the Faker instance is in multi-locale mode and at the same time `Faker.seed` was called with a value other than `None`.

Faker 15.3.2
Python 3.11.0
Ubuntu 22.04
I stepped through the following script in the debugger:

```python
from faker import Faker

fake = Faker(['en_US', 'cs_CZ'])
Faker.seed(42)

for _ in range(5):
    print(fake.name())
```

and found that this line:
https://github.com/joke2k/faker/blob/v15.3.2/faker/proxy.py#L157

is executed on each iteration of the loop, i.e. the generator is re-seeded (with the same value 42) on each call to `fake.name()`. That seems to be the cause of the above shown behavior.
Today I found a test (added as part of #1630) that actually expects this behavior:
https://github.com/joke2k/faker/blob/v15.3.2/tests/test_proxy.py#L131

Nice find @mportesdev - I'm curious what the logic was then in this commit: 
https://github.com/joke2k/faker/commit/5128ae645766d3768370758df2f5002ce0284bc4

@fcurella since you made the change could you elaborate? Is this check actually necessary since `Faker.seed()` calls `Generator.seed()` which calls `random.seed()` anyway and it's working on the same `Random` instance.

Resolving patch:
diff --git a/faker/proxy.py b/faker/proxy.py
--- a/faker/proxy.py
+++ b/faker/proxy.py
@@ -9,7 +9,7 @@
 from .config import DEFAULT_LOCALE
 from .exceptions import UniquenessException
 from .factory import Factory
-from .generator import Generator, Sentinel, random
+from .generator import Generator, random
 from .typing import SeedType
 from .utils.distribution import choices_distribution
 
@@ -153,8 +153,6 @@ def _select_factory(self, method_name: str) -> Factory:
         elif len(factories) == 1:
             return factories[0]
 
-        if Generator._global_seed is not Sentinel:
-            random.seed(Generator._global_seed)  # type: ignore
         if weights:
             factory = self._select_factory_distribution(factories, weights)
         else:


Test patch:
diff --git a/tests/test_proxy.py b/tests/test_proxy.py
--- a/tests/test_proxy.py
+++ b/tests/test_proxy.py
@@ -130,11 +130,18 @@ def test_seed_classmethod(self):
 
     def test_seed_class_locales(self):
         Faker.seed(2043)
+        count = 5
         fake = Faker(["en_GB", "fr_FR", "en_IN"])
-        name = fake.name()
+        first_list = [fake.name() for _ in range(count)]
+        # We convert the list to a set to remove duplicates and ensure
+        # that we have exactly `count` unique fake values
+        assert len(set(first_list)) == count
 
-        for _ in range(5):
-            assert fake.name() == name
+        Faker.seed(2043)
+        fake = Faker(["en_GB", "fr_FR", "en_IN"])
+        second_list = [fake.name() for _ in range(count)]
+
+        assert first_list == second_list
 
     def test_seed_instance(self):
         locale = ["de_DE", "en-US", "en-PH", "ja_JP"]