prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Reseed code broke in 0.8 unnecessarily
  Commit ea4f189bbff1925d7a7e2d7cbc6e91e2e8a9a3f3 changed the name of the `random.Random()` object in `faker.generator` from `random` to `mod_random`, re-exposing the `random` module as the name `faker.generator.random`. This broke code like:
  
  ```py
  from faker.generator import random
  random.seed(1)
  ``` 
  
  which is basically what my `pytest-randomly` plugin does. At first I thought this was #586 but then I saw that every run was broken. The failure is silent because `random` is still a name in `faker.generator`, it just now points at the global `random` module 😱
  
  I suggest just doing some renaming in the module to fix this so old code continues to work.
  
  </issue>
  <code>
  [start of faker/utils/distribution.py]
  1 # coding=utf-8
  2 
  3 import bisect
  4 from faker.generator import mod_random
  5 
  6 def random_sample(random=None):
  7     if random is None:
  8         random = mod_random
  9     return random.uniform(0.0, 1.0)
  10 
  11 
  12 def cumsum(it):
  13     total = 0
  14     for x in it:
  15         total += x
  16         yield total
  17 
  18 
  19 def choice_distribution(a, p, random=None):
  20     if random is None:
  21         random = mod_random
  22 
  23     assert len(a) == len(p)
  24 
  25     if hasattr(random, 'choices'):
  26         return random.choices(a, weights=p)[0]
  27     else:
  28         cdf = list(cumsum(p))
  29         normal = cdf[-1]
  30         cdf2 = [float(i) / float(normal) for i in cdf]
  31         uniform_sample = random_sample(random=random)
  32         idx = bisect.bisect_right(cdf2, uniform_sample)
  33         return a[idx]
  34
  [end of faker/utils/distribution.py]
  [start of faker/generator.py]
  1 # coding=utf-8
  2 
  3 from __future__ import unicode_literals
  4 
  5 import re
  6 import random
  7 
  8 
  9 _re_token = re.compile(r'\{\{(\s?)(\w+)(\s?)\}\}')
  10 mod_random = random.Random()
  11 
  12 
  13 class Generator(object):
  14 
  15     __config = {}
  16 
  17     def __init__(self, **config):
  18         self.providers = []
  19         self.__config = dict(
  20             list(self.__config.items()) + list(config.items()))
  21         self.__random = mod_random
  22 
  23     def add_provider(self, provider):
  24 
  25         if type(provider) is type:
  26             provider = provider(self)
  27 
  28         self.providers.insert(0, provider)
  29 
  30         for method_name in dir(provider):
  31             # skip 'private' method
  32             if method_name.startswith('_'):
  33                 continue
  34 
  35             faker_function = getattr(provider, method_name)
  36 
  37             if hasattr(faker_function, '__call__') or \
  38                     isinstance(faker_function, (classmethod, staticmethod)):
  39                 # add all faker method to generator
  40                 self.set_formatter(method_name, faker_function)
  41 
  42     def provider(self, name):
  43         try:
  44             lst = [p for p in self.get_providers()
  45                    if p.__provider__ == name.lower()]
  46             return lst[0]
  47         except IndexError:
  48             return None
  49 
  50     def get_providers(self):
  51         """Returns added providers."""
  52         return self.providers
  53 
  54     @property
  55     def random(self):
  56         return self.__random
  57 
  58     def seed_instance(self, seed=None):
  59         """Calls random.seed"""
  60         if self.__random == mod_random:
  61             # create per-instance random obj when first time seed_instance() is called
  62             self.__random = random.Random()
  63         self.__random.seed(seed)
  64 
  65     @classmethod
  66     def seed(cls, seed=None):
  67         mod_random.seed(seed)
  68 
  69     def format(self, formatter, *args, **kwargs):
  70         """
  71         This is a secure way to make a fake from another Provider.
  72         """
  73         # TODO: data export?
  74         return self.get_formatter(formatter)(*args, **kwargs)
  75 
  76     def get_formatter(self, formatter):
  77         try:
  78             return getattr(self, formatter)
  79         except AttributeError:
  80             if 'locale' in self.__config:
  81                 msg = 'Unknown formatter "{0}" with locale "{1}"'.format(
  82                     formatter, self.__config['locale']
  83                 )
  84             else:
  85                 raise AttributeError('Unknown formatter "{0}"'.format(
  86                     formatter
  87                 ))
  88             raise AttributeError(msg)
  89 
  90     def set_formatter(self, name, method):
  91         """
  92         This method adds a provider method to generator.
  93         Override this method to add some decoration or logging stuff.
  94         """
  95         setattr(self, name, method)
  96 
  97     def parse(self, text):
  98         """
  99         Replaces tokens (like '{{ tokenName }}' or '{{tokenName}}')
  100         with the result from the token method call.
  101         """
  102         return _re_token.sub(self.__format_token, text)
  103 
  104     def __format_token(self, matches):
  105         formatter = list(matches.groups())
  106         formatter[1] = self.format(formatter[1])
  107         return ''.join(formatter)
  108
  [end of faker/generator.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/faker/generator.py b/faker/generator.py
  --- a/faker/generator.py
  +++ b/faker/generator.py
  @@ -3,11 +3,12 @@
   from __future__ import unicode_literals
   
   import re
  -import random
  +import random as random_module
   
   
   _re_token = re.compile(r'\{\{(\s?)(\w+)(\s?)\}\}')
  -mod_random = random.Random()
  +random = random_module.Random()
  +mod_random = random  # compat with name released in 0.8
   
   
   class Generator(object):
  @@ -18,7 +19,7 @@
           self.providers = []
           self.__config = dict(
               list(self.__config.items()) + list(config.items()))
  -        self.__random = mod_random
  +        self.__random = random
   
       def add_provider(self, provider):
   
  @@ -57,14 +58,14 @@
   
       def seed_instance(self, seed=None):
           """Calls random.seed"""
  -        if self.__random == mod_random:
  +        if self.__random == random:
               # create per-instance random obj when first time seed_instance() is called
  -            self.__random = random.Random()
  +            self.__random = random_module.Random()
           self.__random.seed(seed)
   
       @classmethod
       def seed(cls, seed=None):
  -        mod_random.seed(seed)
  +        random.seed(seed)
   
       def format(self, formatter, *args, **kwargs):
           """
  diff --git a/faker/utils/distribution.py b/faker/utils/distribution.py
  --- a/faker/utils/distribution.py
  +++ b/faker/utils/distribution.py
  @@ -1,7 +1,8 @@
   # coding=utf-8
   
   import bisect
  -from faker.generator import mod_random
  +from faker.generator import random as mod_random
  +
   
   def random_sample(random=None):
       if random is None:
  
verification_info: {"golden_diff": "diff --git a/faker/generator.py b/faker/generator.py\n--- a/faker/generator.py\n+++ b/faker/generator.py\n@@ -3,11 +3,12 @@\n from __future__ import unicode_literals\n \n import re\n-import random\n+import random as random_module\n \n \n _re_token = re.compile(r'\\{\\{(\\s?)(\\w+)(\\s?)\\}\\}')\n-mod_random = random.Random()\n+random = random_module.Random()\n+mod_random = random  # compat with name released in 0.8\n \n \n class Generator(object):\n@@ -18,7 +19,7 @@\n         self.providers = []\n         self.__config = dict(\n             list(self.__config.items()) + list(config.items()))\n-        self.__random = mod_random\n+        self.__random = random\n \n     def add_provider(self, provider):\n \n@@ -57,14 +58,14 @@\n \n     def seed_instance(self, seed=None):\n         \"\"\"Calls random.seed\"\"\"\n-        if self.__random == mod_random:\n+        if self.__random == random:\n             # create per-instance random obj when first time seed_instance() is called\n-            self.__random = random.Random()\n+            self.__random = random_module.Random()\n         self.__random.seed(seed)\n \n     @classmethod\n     def seed(cls, seed=None):\n-        mod_random.seed(seed)\n+        random.seed(seed)\n \n     def format(self, formatter, *args, **kwargs):\n         \"\"\"\ndiff --git a/faker/utils/distribution.py b/faker/utils/distribution.py\n--- a/faker/utils/distribution.py\n+++ b/faker/utils/distribution.py\n@@ -1,7 +1,8 @@\n # coding=utf-8\n \n import bisect\n-from faker.generator import mod_random\n+from faker.generator import random as mod_random\n+\n \n def random_sample(random=None):\n     if random is None:\n", "issue": "Reseed code broke in 0.8 unnecessarily\nCommit ea4f189bbff1925d7a7e2d7cbc6e91e2e8a9a3f3 changed the name of the `random.Random()` object in `faker.generator` from `random` to `mod_random`, re-exposing the `random` module as the name `faker.generator.random`. This broke code like:\r\n\r\n```py\r\nfrom faker.generator import random\r\nrandom.seed(1)\r\n``` \r\n\r\nwhich is basically what my `pytest-randomly` plugin does. At first I thought this was #586 but then I saw that every run was broken. The failure is silent because `random` is still a name in `faker.generator`, it just now points at the global `random` module \ud83d\ude31\r\n\r\nI suggest just doing some renaming in the module to fix this so old code continues to work.\n", "before_files": [{"content": "# coding=utf-8\n\nimport bisect\nfrom faker.generator import mod_random\n\ndef random_sample(random=None):\n    if random is None:\n        random = mod_random\n    return random.uniform(0.0, 1.0)\n\n\ndef cumsum(it):\n    total = 0\n    for x in it:\n        total += x\n        yield total\n\n\ndef choice_distribution(a, p, random=None):\n    if random is None:\n        random = mod_random\n\n    assert len(a) == len(p)\n\n    if hasattr(random, 'choices'):\n        return random.choices(a, weights=p)[0]\n    else:\n        cdf = list(cumsum(p))\n        normal = cdf[-1]\n        cdf2 = [float(i) / float(normal) for i in cdf]\n        uniform_sample = random_sample(random=random)\n        idx = bisect.bisect_right(cdf2, uniform_sample)\n        return a[idx]\n", "path": "faker/utils/distribution.py"}, {"content": "# coding=utf-8\n\nfrom __future__ import unicode_literals\n\nimport re\nimport random\n\n\n_re_token = re.compile(r'\\{\\{(\\s?)(\\w+)(\\s?)\\}\\}')\nmod_random = random.Random()\n\n\nclass Generator(object):\n\n    __config = {}\n\n    def __init__(self, **config):\n        self.providers = []\n        self.__config = dict(\n            list(self.__config.items()) + list(config.items()))\n        self.__random = mod_random\n\n    def add_provider(self, provider):\n\n        if type(provider) is type:\n            provider = provider(self)\n\n        self.providers.insert(0, provider)\n\n        for method_name in dir(provider):\n            # skip 'private' method\n            if method_name.startswith('_'):\n                continue\n\n            faker_function = getattr(provider, method_name)\n\n            if hasattr(faker_function, '__call__') or \\\n                    isinstance(faker_function, (classmethod, staticmethod)):\n                # add all faker method to generator\n                self.set_formatter(method_name, faker_function)\n\n    def provider(self, name):\n        try:\n            lst = [p for p in self.get_providers()\n                   if p.__provider__ == name.lower()]\n            return lst[0]\n        except IndexError:\n            return None\n\n    def get_providers(self):\n        \"\"\"Returns added providers.\"\"\"\n        return self.providers\n\n    @property\n    def random(self):\n        return self.__random\n\n    def seed_instance(self, seed=None):\n        \"\"\"Calls random.seed\"\"\"\n        if self.__random == mod_random:\n            # create per-instance random obj when first time seed_instance() is called\n            self.__random = random.Random()\n        self.__random.seed(seed)\n\n    @classmethod\n    def seed(cls, seed=None):\n        mod_random.seed(seed)\n\n    def format(self, formatter, *args, **kwargs):\n        \"\"\"\n        This is a secure way to make a fake from another Provider.\n        \"\"\"\n        # TODO: data export?\n        return self.get_formatter(formatter)(*args, **kwargs)\n\n    def get_formatter(self, formatter):\n        try:\n            return getattr(self, formatter)\n        except AttributeError:\n            if 'locale' in self.__config:\n                msg = 'Unknown formatter \"{0}\" with locale \"{1}\"'.format(\n                    formatter, self.__config['locale']\n                )\n            else:\n                raise AttributeError('Unknown formatter \"{0}\"'.format(\n                    formatter\n                ))\n            raise AttributeError(msg)\n\n    def set_formatter(self, name, method):\n        \"\"\"\n        This method adds a provider method to generator.\n        Override this method to add some decoration or logging stuff.\n        \"\"\"\n        setattr(self, name, method)\n\n    def parse(self, text):\n        \"\"\"\n        Replaces tokens (like '{{ tokenName }}' or '{{tokenName}}')\n        with the result from the token method call.\n        \"\"\"\n        return _re_token.sub(self.__format_token, text)\n\n    def __format_token(self, matches):\n        formatter = list(matches.groups())\n        formatter[1] = self.format(formatter[1])\n        return ''.join(formatter)\n", "path": "faker/generator.py"}]}