prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Brazilian RG (identity card)
  Add Generator to Brazilian RG (identity card)
  
  ### Steps to reproduce
  fake = Faker('pt_Br')
  fake.rg()
  
  ### Expected behavior
  return like this rules:
  https://www.ngmatematica.com/2014/02/como-determinar-o-digito-verificador-do.html
  8 digits + 1 checksum digit
  ### Actual behavior
  New feature
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `faker/providers/ssn/pt_BR/__init__.py`
  Content:
  ```
  1 # coding=utf-8
  2 
  3 from __future__ import unicode_literals
  4 from .. import Provider as SsnProvider
  5 
  6 
  7 def checksum(digits):
  8     """
  9     Returns the checksum of CPF digits.
  10     References to the algorithm:
  11     https://pt.wikipedia.org/wiki/Cadastro_de_pessoas_f%C3%ADsicas#Algoritmo
  12     https://metacpan.org/source/MAMAWE/Algorithm-CheckDigits-v1.3.0/lib/Algorithm/CheckDigits/M11_004.pm
  13     """
  14     s = 0
  15     p = len(digits) + 1
  16     for i in range(0, len(digits)):
  17         s += digits[i] * p
  18         p -= 1
  19 
  20     reminder = s % 11
  21     if reminder == 0 or reminder == 1:
  22         return 0
  23     else:
  24         return 11 - reminder
  25 
  26 
  27 class Provider(SsnProvider):
  28     """
  29     Provider for Brazilian SSN also known in Brazil as CPF.
  30     There are two methods Provider.ssn and Provider.cpf
  31     The snn returns a valid number with numbers only
  32     The cpf return a valid number formatted with brazilian mask. eg nnn.nnn.nnn-nn
  33     """
  34 
  35     def ssn(self):
  36         digits = self.generator.random.sample(range(10), 9)
  37 
  38         dv = checksum(digits)
  39         digits.append(dv)
  40         digits.append(checksum(digits))
  41 
  42         return ''.join(map(str, digits))
  43 
  44     def cpf(self):
  45         c = self.ssn()
  46         return c[:3] + '.' + c[3:6] + '.' + c[6:9] + '-' + c[9:]
  47
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/faker/providers/ssn/pt_BR/__init__.py b/faker/providers/ssn/pt_BR/__init__.py
  --- a/faker/providers/ssn/pt_BR/__init__.py
  +++ b/faker/providers/ssn/pt_BR/__init__.py
  @@ -1,6 +1,7 @@
   # coding=utf-8
   
   from __future__ import unicode_literals
  +
   from .. import Provider as SsnProvider
   
   
  @@ -44,3 +45,22 @@
       def cpf(self):
           c = self.ssn()
           return c[:3] + '.' + c[3:6] + '.' + c[6:9] + '-' + c[9:]
  +
  +    def rg(self):
  +        """
  +        Brazilian RG, return plain numbers.
  +        Check:  https://www.ngmatematica.com/2014/02/como-determinar-o-digito-verificador-do.html
  +        """
  +
  +        digits = self.generator.random.sample(range(0, 9), 8)
  +        checksum = sum(i * digits[i - 2] for i in range(2, 10))
  +        last_digit = 11 - (checksum % 11)
  +
  +        if last_digit == 10:
  +            digits.append('X')
  +        elif last_digit == 11:
  +            digits.append(0)
  +        else:
  +            digits.append(last_digit)
  +
  +        return ''.join(map(str, digits))
  
verification_info: {"golden_diff": "diff --git a/faker/providers/ssn/pt_BR/__init__.py b/faker/providers/ssn/pt_BR/__init__.py\n--- a/faker/providers/ssn/pt_BR/__init__.py\n+++ b/faker/providers/ssn/pt_BR/__init__.py\n@@ -1,6 +1,7 @@\n # coding=utf-8\n \n from __future__ import unicode_literals\n+\n from .. import Provider as SsnProvider\n \n \n@@ -44,3 +45,22 @@\n     def cpf(self):\n         c = self.ssn()\n         return c[:3] + '.' + c[3:6] + '.' + c[6:9] + '-' + c[9:]\n+\n+    def rg(self):\n+        \"\"\"\n+        Brazilian RG, return plain numbers.\n+        Check:  https://www.ngmatematica.com/2014/02/como-determinar-o-digito-verificador-do.html\n+        \"\"\"\n+\n+        digits = self.generator.random.sample(range(0, 9), 8)\n+        checksum = sum(i * digits[i - 2] for i in range(2, 10))\n+        last_digit = 11 - (checksum % 11)\n+\n+        if last_digit == 10:\n+            digits.append('X')\n+        elif last_digit == 11:\n+            digits.append(0)\n+        else:\n+            digits.append(last_digit)\n+\n+        return ''.join(map(str, digits))\n", "issue": "Brazilian RG (identity card)\nAdd Generator to Brazilian RG (identity card)\r\n\r\n### Steps to reproduce\r\nfake = Faker('pt_Br')\r\nfake.rg()\r\n\r\n### Expected behavior\r\nreturn like this rules:\r\nhttps://www.ngmatematica.com/2014/02/como-determinar-o-digito-verificador-do.html\r\n8 digits + 1 checksum digit\r\n### Actual behavior\r\nNew feature\r\n\n", "before_files": [{"content": "# coding=utf-8\n\nfrom __future__ import unicode_literals\nfrom .. import Provider as SsnProvider\n\n\ndef checksum(digits):\n    \"\"\"\n    Returns the checksum of CPF digits.\n    References to the algorithm:\n    https://pt.wikipedia.org/wiki/Cadastro_de_pessoas_f%C3%ADsicas#Algoritmo\n    https://metacpan.org/source/MAMAWE/Algorithm-CheckDigits-v1.3.0/lib/Algorithm/CheckDigits/M11_004.pm\n    \"\"\"\n    s = 0\n    p = len(digits) + 1\n    for i in range(0, len(digits)):\n        s += digits[i] * p\n        p -= 1\n\n    reminder = s % 11\n    if reminder == 0 or reminder == 1:\n        return 0\n    else:\n        return 11 - reminder\n\n\nclass Provider(SsnProvider):\n    \"\"\"\n    Provider for Brazilian SSN also known in Brazil as CPF.\n    There are two methods Provider.ssn and Provider.cpf\n    The snn returns a valid number with numbers only\n    The cpf return a valid number formatted with brazilian mask. eg nnn.nnn.nnn-nn\n    \"\"\"\n\n    def ssn(self):\n        digits = self.generator.random.sample(range(10), 9)\n\n        dv = checksum(digits)\n        digits.append(dv)\n        digits.append(checksum(digits))\n\n        return ''.join(map(str, digits))\n\n    def cpf(self):\n        c = self.ssn()\n        return c[:3] + '.' + c[3:6] + '.' + c[6:9] + '-' + c[9:]\n", "path": "faker/providers/ssn/pt_BR/__init__.py"}], "after_files": [{"content": "# coding=utf-8\n\nfrom __future__ import unicode_literals\n\nfrom .. import Provider as SsnProvider\n\n\ndef checksum(digits):\n    \"\"\"\n    Returns the checksum of CPF digits.\n    References to the algorithm:\n    https://pt.wikipedia.org/wiki/Cadastro_de_pessoas_f%C3%ADsicas#Algoritmo\n    https://metacpan.org/source/MAMAWE/Algorithm-CheckDigits-v1.3.0/lib/Algorithm/CheckDigits/M11_004.pm\n    \"\"\"\n    s = 0\n    p = len(digits) + 1\n    for i in range(0, len(digits)):\n        s += digits[i] * p\n        p -= 1\n\n    reminder = s % 11\n    if reminder == 0 or reminder == 1:\n        return 0\n    else:\n        return 11 - reminder\n\n\nclass Provider(SsnProvider):\n    \"\"\"\n    Provider for Brazilian SSN also known in Brazil as CPF.\n    There are two methods Provider.ssn and Provider.cpf\n    The snn returns a valid number with numbers only\n    The cpf return a valid number formatted with brazilian mask. eg nnn.nnn.nnn-nn\n    \"\"\"\n\n    def ssn(self):\n        digits = self.generator.random.sample(range(10), 9)\n\n        dv = checksum(digits)\n        digits.append(dv)\n        digits.append(checksum(digits))\n\n        return ''.join(map(str, digits))\n\n    def cpf(self):\n        c = self.ssn()\n        return c[:3] + '.' + c[3:6] + '.' + c[6:9] + '-' + c[9:]\n\n    def rg(self):\n        \"\"\"\n        Brazilian RG, return plain numbers.\n        Check:  https://www.ngmatematica.com/2014/02/como-determinar-o-digito-verificador-do.html\n        \"\"\"\n\n        digits = self.generator.random.sample(range(0, 9), 8)\n        checksum = sum(i * digits[i - 2] for i in range(2, 10))\n        last_digit = 11 - (checksum % 11)\n\n        if last_digit == 10:\n            digits.append('X')\n        elif last_digit == 11:\n            digits.append(0)\n        else:\n            digits.append(last_digit)\n\n        return ''.join(map(str, digits))\n", "path": "faker/providers/ssn/pt_BR/__init__.py"}]}