prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  cupy.random.permutation() overwrites its argument.
  `cupy.random.permutation()` overwrites its argument.
  This is incompatible with `numpy.random.permutation`.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `cupy/random/permutations.py`
  Content:
  ```
  1 from cupy.random import generator
  2 import six
  3 
  4 
  5 def shuffle(a):
  6     """Shuffles an array.
  7 
  8     Args:
  9         a (cupy.ndarray): The array to be shuffled.
  10 
  11     .. seealso:: :func:`numpy.random.shuffle`
  12 
  13     """
  14     rs = generator.get_random_state()
  15     return rs.shuffle(a)
  16 
  17 
  18 def permutation(a):
  19     """Returns a permuted range or shuffles an array."""
  20     if isinstance(a, six.integer_types):
  21         rs = generator.get_random_state()
  22         return rs.permutation(a)
  23     else:
  24         return shuffle(a)
  25
  ```
  --- 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/cupy/random/permutations.py b/cupy/random/permutations.py
  --- a/cupy/random/permutations.py
  +++ b/cupy/random/permutations.py
  @@ -16,9 +16,20 @@
   
   
   def permutation(a):
  -    """Returns a permuted range or shuffles an array."""
  +    """Returns a permuted range or a permutation of an array.
  +
  +    Args:
  +        a (int or cupy.ndarray): The range or the array to be shuffled.
  +
  +    Returns:
  +        cupy.ndarray: If `a` is an integer, it is permutation range between 0
  +        and `a` - 1.
  +        Otherwise, it is a permutation of `a`.
  +
  +    .. seealso:: :func:`numpy.random.permutation`
  +    """
  +    rs = generator.get_random_state()
       if isinstance(a, six.integer_types):
  -        rs = generator.get_random_state()
           return rs.permutation(a)
       else:
  -        return shuffle(a)
  +        return a[rs.permutation(len(a))]
  
verification_info: {"golden_diff": "diff --git a/cupy/random/permutations.py b/cupy/random/permutations.py\n--- a/cupy/random/permutations.py\n+++ b/cupy/random/permutations.py\n@@ -16,9 +16,20 @@\n \n \n def permutation(a):\n-    \"\"\"Returns a permuted range or shuffles an array.\"\"\"\n+    \"\"\"Returns a permuted range or a permutation of an array.\n+\n+    Args:\n+        a (int or cupy.ndarray): The range or the array to be shuffled.\n+\n+    Returns:\n+        cupy.ndarray: If `a` is an integer, it is permutation range between 0\n+        and `a` - 1.\n+        Otherwise, it is a permutation of `a`.\n+\n+    .. seealso:: :func:`numpy.random.permutation`\n+    \"\"\"\n+    rs = generator.get_random_state()\n     if isinstance(a, six.integer_types):\n-        rs = generator.get_random_state()\n         return rs.permutation(a)\n     else:\n-        return shuffle(a)\n+        return a[rs.permutation(len(a))]\n", "issue": "cupy.random.permutation() overwrites its argument.\n`cupy.random.permutation()` overwrites its argument.\r\nThis is incompatible with `numpy.random.permutation`.\r\n\n", "before_files": [{"content": "from cupy.random import generator\nimport six\n\n\ndef shuffle(a):\n    \"\"\"Shuffles an array.\n\n    Args:\n        a (cupy.ndarray): The array to be shuffled.\n\n    .. seealso:: :func:`numpy.random.shuffle`\n\n    \"\"\"\n    rs = generator.get_random_state()\n    return rs.shuffle(a)\n\n\ndef permutation(a):\n    \"\"\"Returns a permuted range or shuffles an array.\"\"\"\n    if isinstance(a, six.integer_types):\n        rs = generator.get_random_state()\n        return rs.permutation(a)\n    else:\n        return shuffle(a)\n", "path": "cupy/random/permutations.py"}], "after_files": [{"content": "from cupy.random import generator\nimport six\n\n\ndef shuffle(a):\n    \"\"\"Shuffles an array.\n\n    Args:\n        a (cupy.ndarray): The array to be shuffled.\n\n    .. seealso:: :func:`numpy.random.shuffle`\n\n    \"\"\"\n    rs = generator.get_random_state()\n    return rs.shuffle(a)\n\n\ndef permutation(a):\n    \"\"\"Returns a permuted range or a permutation of an array.\n\n    Args:\n        a (int or cupy.ndarray): The range or the array to be shuffled.\n\n    Returns:\n        cupy.ndarray: If `a` is an integer, it is permutation range between 0\n        and `a` - 1.\n        Otherwise, it is a permutation of `a`.\n\n    .. seealso:: :func:`numpy.random.permutation`\n    \"\"\"\n    rs = generator.get_random_state()\n    if isinstance(a, six.integer_types):\n        return rs.permutation(a)\n    else:\n        return a[rs.permutation(len(a))]\n", "path": "cupy/random/permutations.py"}]}