We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Seed cannot be fixed via an environment variable
Past version of Chainer supported the CHAINER_SEED environment variable, which is (maybe accidentally) missed in v1.3.0.


--- 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/generator.py`
Content:
```
1 import atexit
2 import binascii
3 import collections
4 import os
5 import time
6 
7 import numpy
8 
9 import cupy
10 from cupy import cuda
11 from cupy.cuda import curand
12 from cupy import elementwise
13 
14 
15 class RandomState(object):
16 
17     """Portable container of a pseudo-random number generator.
18 
19     An instance of this class holds the state of a random number generator. The
20     state is available only on the device which has been current at the
21     initialization of the instance.
22 
23     Functions of :mod:`cupy.random` use global instances of this class.
24     Different instances are used for different devices. The global state for
25     the current device can be obtained by the
26     :func:`cupy.random.get_random_state` function.
27 
28     Args:
29         seed (None or int): Seed of the random number generator. See the
30             :meth:`~cupy.random.RandomState.seed` method for detail.
31         method (int): Method of the random number generator. Following values
32             are available::
33 
34                cupy.cuda.curand.CURAND_RNG_PSEUDO_DEFAULT
35                cupy.cuda.curand.CURAND_RNG_XORWOW
36                cupy.cuda.curand.CURAND_RNG_MRG32K3A
37                cupy.cuda.curand.CURAND_RNG_MTGP32
38                cupy.cuda.curand.CURAND_RNG_MT19937
39                cupy.cuda.curand.CURAND_RNG_PHILOX4_32_10
40 
41     """
42     def __init__(self, seed=None, method=curand.CURAND_RNG_PSEUDO_DEFAULT):
43         self._generator = curand.createGenerator(method)
44         self.seed(seed)
45 
46     def __del__(self):
47         curand.destroyGenerator(self._generator)
48 
49     def set_stream(self, stream=None):
50         if stream is None:
51             stream = cuda.Stream()
52         curand.setStream(self._generator, stream.ptr)
53 
54     # NumPy compatible functions
55 
56     def lognormal(self, mean=0.0, sigma=1.0, size=None, dtype=float):
57         """Returns an array of samples drawn from a log normal distribution.
58 
59         .. seealso::
60             :func:`cupy.random.lognormal` for full documentation,
61             :meth:`numpy.random.RandomState.lognormal`
62 
63         """
64         dtype = _check_and_get_dtype(dtype)
65         size = _get_size(size)
66         out = cupy.empty(size, dtype=dtype)
67         if dtype.char == 'f':
68             func = curand.generateLogNormal
69         else:
70             func = curand.generateLogNormalDouble
71         func(self._generator, out.data.ptr, out.size, mean, sigma)
72         return out
73 
74     def normal(self, loc=0.0, scale=1.0, size=None, dtype=float):
75         """Returns an array of normally distributed samples.
76 
77         .. seealso::
78             :func:`cupy.random.normal` for full documentation,
79             :meth:`numpy.random.RandomState.normal`
80 
81         """
82         dtype = _check_and_get_dtype(dtype)
83         size = _get_size(size)
84         out = cupy.empty(size, dtype=dtype)
85         if dtype.char == 'f':
86             func = curand.generateNormal
87         else:
88             func = curand.generateNormalDouble
89         func(self._generator, out.data.ptr, out.size, loc, scale)
90         return out
91 
92     def rand(self, *size, **kwarg):
93         """Returns uniform random values over the interval ``[0, 1)``.
94 
95         .. seealso::
96             :func:`cupy.random.rand` for full documentation,
97             :meth:`numpy.random.RandomState.rand`
98 
99         """
100         dtype = kwarg.pop('dtype', float)
101         if kwarg:
102             raise TypeError('rand() got unexpected keyword arguments %s'
103                             % ', '.join(kwarg.keys()))
104         return self.random_sample(size=size, dtype=dtype)
105 
106     def randn(self, *size, **kwarg):
107         """Returns an array of standand normal random values.
108 
109         .. seealso::
110             :func:`cupy.random.randn` for full documentation,
111             :meth:`numpy.random.RandomState.randn`
112 
113         """
114         dtype = kwarg.pop('dtype', float)
115         if kwarg:
116             raise TypeError('randn() got unexpected keyword arguments %s'
117                             % ', '.join(kwarg.keys()))
118         return self.normal(size=size, dtype=dtype)
119 
120     _1m_kernel = elementwise.ElementwiseKernel(
121         '', 'T x', 'x = 1 - x', 'cupy_random_1_minus_x')
122 
123     def random_sample(self, size=None, dtype=float):
124         """Returns an array of random values over the interval ``[0, 1)``.
125 
126         .. seealso::
127             :func:`cupy.random.random_sample` for full documentation,
128             :meth:`numpy.random.RandomState.random_sample`
129 
130         """
131         dtype = _check_and_get_dtype(dtype)
132         size = _get_size(size)
133         out = cupy.empty(size, dtype=dtype)
134         if dtype.char == 'f':
135             func = curand.generateUniform
136         else:
137             func = curand.generateUniformDouble
138         func(self._generator, out.data.ptr, out.size)
139         RandomState._1m_kernel(out)
140         return out
141 
142     def seed(self, seed=None):
143         """Resets the state of the random number generator with a seed.
144 
145         ..seealso::
146             :func:`cupy.random.seed` for full documentation,
147             :meth:`numpy.random.RandomState.seed`
148 
149         """
150         if seed is None:
151             try:
152                 seed_str = binascii.hexlify(os.urandom(8))
153                 seed = numpy.uint64(int(seed_str, 16))
154             except NotImplementedError:
155                 seed = numpy.uint64(time.clock() * 1000000)
156         else:
157             seed = numpy.uint64(seed)
158 
159         curand.setPseudoRandomGeneratorSeed(self._generator, seed)
160 
161     def standard_normal(self, size=None, dtype=float):
162         """Returns samples drawn from the standard normal distribution.
163 
164         .. seealso::
165             :func:`cupy.random.standard_normal` for full documentation,
166             :meth:`numpy.random.RandomState.standard_normal`
167 
168         """
169         return self.normal(size=size, dtype=dtype)
170 
171     def uniform(self, low=0.0, high=1.0, size=None, dtype=float):
172         """Returns an array of uniformlly-distributed samples over an interval.
173 
174         .. seealso::
175             :func:`cupy.random.uniform` for full documentation,
176             :meth:`numpy.random.RandomState.uniform`
177 
178         """
179         dtype = numpy.dtype(dtype)
180         size = _get_size(size)
181         rand = self.random_sample(size=size, dtype=dtype)
182         return dtype.type(low) + rand * dtype.type(high - low)
183 
184 
185 def seed(seed=None):
186     """Resets the state of the random number generator with a seed.
187 
188     This function resets the state of the global random number generator for
189     the current device. Be careful that generators for other devices are not
190     affected.
191 
192     Args:
193         seed (None or int): Seed for the random number generator. If None, it
194             uses :func:`os.urandom` if available or :func:`time.clock`
195             otherwise. Note that this function does not support seeding by an
196             integer array.
197 
198     """
199     get_random_state().seed(seed)
200 
201 
202 # CuPy specific functions
203 
204 _random_states = {}
205 
206 
207 @atexit.register
208 def reset_states():
209     global _random_states
210     _random_states = {}
211 
212 
213 def get_random_state():
214     """Gets the state of the random number generator for the current device.
215 
216     If the state for the current device is not created yet, this function
217     creates a new one, initializes it, and stores it as the state for the
218     current device.
219 
220     Returns:
221         RandomState: The state of the random number generator for the
222         device.
223 
224     """
225     global _random_states
226     dev = cuda.Device()
227     rs = _random_states.get(dev.id, None)
228     if rs is None:
229         rs = RandomState()
230         _random_states[dev.id] = rs
231     return rs
232 
233 
234 def _get_size(size):
235     if size is None:
236         return ()
237     elif isinstance(size, collections.Sequence):
238         return tuple(size)
239     elif isinstance(size, int):
240         return size,
241     else:
242         raise ValueError('size should be None, collections.Sequence, or int')
243 
244 
245 def _check_and_get_dtype(dtype):
246     dtype = numpy.dtype(dtype)
247     if dtype.char not in ('f', 'd'):
248         raise TypeError('cupy.random only supports float32 and float64')
249     return dtype
250
```
--- 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()

```

diff --git a/cupy/random/generator.py b/cupy/random/generator.py
--- a/cupy/random/generator.py
+++ b/cupy/random/generator.py
@@ -226,7 +226,7 @@
     dev = cuda.Device()
     rs = _random_states.get(dev.id, None)
     if rs is None:
-        rs = RandomState()
+        rs = RandomState(os.getenv('CHAINER_SEED'))
         _random_states[dev.id] = rs
     return rs

{"golden_diff": "diff --git a/cupy/random/generator.py b/cupy/random/generator.py\n--- a/cupy/random/generator.py\n+++ b/cupy/random/generator.py\n@@ -226,7 +226,7 @@\n     dev = cuda.Device()\n     rs = _random_states.get(dev.id, None)\n     if rs is None:\n-        rs = RandomState()\n+        rs = RandomState(os.getenv('CHAINER_SEED'))\n         _random_states[dev.id] = rs\n     return rs\n", "issue": "Seed cannot be fixed via an environment variable\nPast version of Chainer supported the CHAINER_SEED environment variable, which is (maybe accidentally) missed in v1.3.0.\n\n", "before_files": [{"content": "import atexit\nimport binascii\nimport collections\nimport os\nimport time\n\nimport numpy\n\nimport cupy\nfrom cupy import cuda\nfrom cupy.cuda import curand\nfrom cupy import elementwise\n\n\nclass RandomState(object):\n\n    \"\"\"Portable container of a pseudo-random number generator.\n\n    An instance of this class holds the state of a random number generator. The\n    state is available only on the device which has been current at the\n    initialization of the instance.\n\n    Functions of :mod:`cupy.random` use global instances of this class.\n    Different instances are used for different devices. The global state for\n    the current device can be obtained by the\n    :func:`cupy.random.get_random_state` function.\n\n    Args:\n        seed (None or int): Seed of the random number generator. See the\n            :meth:`~cupy.random.RandomState.seed` method for detail.\n        method (int): Method of the random number generator. Following values\n            are available::\n\n               cupy.cuda.curand.CURAND_RNG_PSEUDO_DEFAULT\n               cupy.cuda.curand.CURAND_RNG_XORWOW\n               cupy.cuda.curand.CURAND_RNG_MRG32K3A\n               cupy.cuda.curand.CURAND_RNG_MTGP32\n               cupy.cuda.curand.CURAND_RNG_MT19937\n               cupy.cuda.curand.CURAND_RNG_PHILOX4_32_10\n\n    \"\"\"\n    def __init__(self, seed=None, method=curand.CURAND_RNG_PSEUDO_DEFAULT):\n        self._generator = curand.createGenerator(method)\n        self.seed(seed)\n\n    def __del__(self):\n        curand.destroyGenerator(self._generator)\n\n    def set_stream(self, stream=None):\n        if stream is None:\n            stream = cuda.Stream()\n        curand.setStream(self._generator, stream.ptr)\n\n    # NumPy compatible functions\n\n    def lognormal(self, mean=0.0, sigma=1.0, size=None, dtype=float):\n        \"\"\"Returns an array of samples drawn from a log normal distribution.\n\n        .. seealso::\n            :func:`cupy.random.lognormal` for full documentation,\n            :meth:`numpy.random.RandomState.lognormal`\n\n        \"\"\"\n        dtype = _check_and_get_dtype(dtype)\n        size = _get_size(size)\n        out = cupy.empty(size, dtype=dtype)\n        if dtype.char == 'f':\n            func = curand.generateLogNormal\n        else:\n            func = curand.generateLogNormalDouble\n        func(self._generator, out.data.ptr, out.size, mean, sigma)\n        return out\n\n    def normal(self, loc=0.0, scale=1.0, size=None, dtype=float):\n        \"\"\"Returns an array of normally distributed samples.\n\n        .. seealso::\n            :func:`cupy.random.normal` for full documentation,\n            :meth:`numpy.random.RandomState.normal`\n\n        \"\"\"\n        dtype = _check_and_get_dtype(dtype)\n        size = _get_size(size)\n        out = cupy.empty(size, dtype=dtype)\n        if dtype.char == 'f':\n            func = curand.generateNormal\n        else:\n            func = curand.generateNormalDouble\n        func(self._generator, out.data.ptr, out.size, loc, scale)\n        return out\n\n    def rand(self, *size, **kwarg):\n        \"\"\"Returns uniform random values over the interval ``[0, 1)``.\n\n        .. seealso::\n            :func:`cupy.random.rand` for full documentation,\n            :meth:`numpy.random.RandomState.rand`\n\n        \"\"\"\n        dtype = kwarg.pop('dtype', float)\n        if kwarg:\n            raise TypeError('rand() got unexpected keyword arguments %s'\n                            % ', '.join(kwarg.keys()))\n        return self.random_sample(size=size, dtype=dtype)\n\n    def randn(self, *size, **kwarg):\n        \"\"\"Returns an array of standand normal random values.\n\n        .. seealso::\n            :func:`cupy.random.randn` for full documentation,\n            :meth:`numpy.random.RandomState.randn`\n\n        \"\"\"\n        dtype = kwarg.pop('dtype', float)\n        if kwarg:\n            raise TypeError('randn() got unexpected keyword arguments %s'\n                            % ', '.join(kwarg.keys()))\n        return self.normal(size=size, dtype=dtype)\n\n    _1m_kernel = elementwise.ElementwiseKernel(\n        '', 'T x', 'x = 1 - x', 'cupy_random_1_minus_x')\n\n    def random_sample(self, size=None, dtype=float):\n        \"\"\"Returns an array of random values over the interval ``[0, 1)``.\n\n        .. seealso::\n            :func:`cupy.random.random_sample` for full documentation,\n            :meth:`numpy.random.RandomState.random_sample`\n\n        \"\"\"\n        dtype = _check_and_get_dtype(dtype)\n        size = _get_size(size)\n        out = cupy.empty(size, dtype=dtype)\n        if dtype.char == 'f':\n            func = curand.generateUniform\n        else:\n            func = curand.generateUniformDouble\n        func(self._generator, out.data.ptr, out.size)\n        RandomState._1m_kernel(out)\n        return out\n\n    def seed(self, seed=None):\n        \"\"\"Resets the state of the random number generator with a seed.\n\n        ..seealso::\n            :func:`cupy.random.seed` for full documentation,\n            :meth:`numpy.random.RandomState.seed`\n\n        \"\"\"\n        if seed is None:\n            try:\n                seed_str = binascii.hexlify(os.urandom(8))\n                seed = numpy.uint64(int(seed_str, 16))\n            except NotImplementedError:\n                seed = numpy.uint64(time.clock() * 1000000)\n        else:\n            seed = numpy.uint64(seed)\n\n        curand.setPseudoRandomGeneratorSeed(self._generator, seed)\n\n    def standard_normal(self, size=None, dtype=float):\n        \"\"\"Returns samples drawn from the standard normal distribution.\n\n        .. seealso::\n            :func:`cupy.random.standard_normal` for full documentation,\n            :meth:`numpy.random.RandomState.standard_normal`\n\n        \"\"\"\n        return self.normal(size=size, dtype=dtype)\n\n    def uniform(self, low=0.0, high=1.0, size=None, dtype=float):\n        \"\"\"Returns an array of uniformlly-distributed samples over an interval.\n\n        .. seealso::\n            :func:`cupy.random.uniform` for full documentation,\n            :meth:`numpy.random.RandomState.uniform`\n\n        \"\"\"\n        dtype = numpy.dtype(dtype)\n        size = _get_size(size)\n        rand = self.random_sample(size=size, dtype=dtype)\n        return dtype.type(low) + rand * dtype.type(high - low)\n\n\ndef seed(seed=None):\n    \"\"\"Resets the state of the random number generator with a seed.\n\n    This function resets the state of the global random number generator for\n    the current device. Be careful that generators for other devices are not\n    affected.\n\n    Args:\n        seed (None or int): Seed for the random number generator. If None, it\n            uses :func:`os.urandom` if available or :func:`time.clock`\n            otherwise. Note that this function does not support seeding by an\n            integer array.\n\n    \"\"\"\n    get_random_state().seed(seed)\n\n\n# CuPy specific functions\n\n_random_states = {}\n\n\n@atexit.register\ndef reset_states():\n    global _random_states\n    _random_states = {}\n\n\ndef get_random_state():\n    \"\"\"Gets the state of the random number generator for the current device.\n\n    If the state for the current device is not created yet, this function\n    creates a new one, initializes it, and stores it as the state for the\n    current device.\n\n    Returns:\n        RandomState: The state of the random number generator for the\n        device.\n\n    \"\"\"\n    global _random_states\n    dev = cuda.Device()\n    rs = _random_states.get(dev.id, None)\n    if rs is None:\n        rs = RandomState()\n        _random_states[dev.id] = rs\n    return rs\n\n\ndef _get_size(size):\n    if size is None:\n        return ()\n    elif isinstance(size, collections.Sequence):\n        return tuple(size)\n    elif isinstance(size, int):\n        return size,\n    else:\n        raise ValueError('size should be None, collections.Sequence, or int')\n\n\ndef _check_and_get_dtype(dtype):\n    dtype = numpy.dtype(dtype)\n    if dtype.char not in ('f', 'd'):\n        raise TypeError('cupy.random only supports float32 and float64')\n    return dtype\n", "path": "cupy/random/generator.py"}], "after_files": [{"content": "import atexit\nimport binascii\nimport collections\nimport os\nimport time\n\nimport numpy\n\nimport cupy\nfrom cupy import cuda\nfrom cupy.cuda import curand\nfrom cupy import elementwise\n\n\nclass RandomState(object):\n\n    \"\"\"Portable container of a pseudo-random number generator.\n\n    An instance of this class holds the state of a random number generator. The\n    state is available only on the device which has been current at the\n    initialization of the instance.\n\n    Functions of :mod:`cupy.random` use global instances of this class.\n    Different instances are used for different devices. The global state for\n    the current device can be obtained by the\n    :func:`cupy.random.get_random_state` function.\n\n    Args:\n        seed (None or int): Seed of the random number generator. See the\n            :meth:`~cupy.random.RandomState.seed` method for detail.\n        method (int): Method of the random number generator. Following values\n            are available::\n\n               cupy.cuda.curand.CURAND_RNG_PSEUDO_DEFAULT\n               cupy.cuda.curand.CURAND_RNG_XORWOW\n               cupy.cuda.curand.CURAND_RNG_MRG32K3A\n               cupy.cuda.curand.CURAND_RNG_MTGP32\n               cupy.cuda.curand.CURAND_RNG_MT19937\n               cupy.cuda.curand.CURAND_RNG_PHILOX4_32_10\n\n    \"\"\"\n    def __init__(self, seed=None, method=curand.CURAND_RNG_PSEUDO_DEFAULT):\n        self._generator = curand.createGenerator(method)\n        self.seed(seed)\n\n    def __del__(self):\n        curand.destroyGenerator(self._generator)\n\n    def set_stream(self, stream=None):\n        if stream is None:\n            stream = cuda.Stream()\n        curand.setStream(self._generator, stream.ptr)\n\n    # NumPy compatible functions\n\n    def lognormal(self, mean=0.0, sigma=1.0, size=None, dtype=float):\n        \"\"\"Returns an array of samples drawn from a log normal distribution.\n\n        .. seealso::\n            :func:`cupy.random.lognormal` for full documentation,\n            :meth:`numpy.random.RandomState.lognormal`\n\n        \"\"\"\n        dtype = _check_and_get_dtype(dtype)\n        size = _get_size(size)\n        out = cupy.empty(size, dtype=dtype)\n        if dtype.char == 'f':\n            func = curand.generateLogNormal\n        else:\n            func = curand.generateLogNormalDouble\n        func(self._generator, out.data.ptr, out.size, mean, sigma)\n        return out\n\n    def normal(self, loc=0.0, scale=1.0, size=None, dtype=float):\n        \"\"\"Returns an array of normally distributed samples.\n\n        .. seealso::\n            :func:`cupy.random.normal` for full documentation,\n            :meth:`numpy.random.RandomState.normal`\n\n        \"\"\"\n        dtype = _check_and_get_dtype(dtype)\n        size = _get_size(size)\n        out = cupy.empty(size, dtype=dtype)\n        if dtype.char == 'f':\n            func = curand.generateNormal\n        else:\n            func = curand.generateNormalDouble\n        func(self._generator, out.data.ptr, out.size, loc, scale)\n        return out\n\n    def rand(self, *size, **kwarg):\n        \"\"\"Returns uniform random values over the interval ``[0, 1)``.\n\n        .. seealso::\n            :func:`cupy.random.rand` for full documentation,\n            :meth:`numpy.random.RandomState.rand`\n\n        \"\"\"\n        dtype = kwarg.pop('dtype', float)\n        if kwarg:\n            raise TypeError('rand() got unexpected keyword arguments %s'\n                            % ', '.join(kwarg.keys()))\n        return self.random_sample(size=size, dtype=dtype)\n\n    def randn(self, *size, **kwarg):\n        \"\"\"Returns an array of standand normal random values.\n\n        .. seealso::\n            :func:`cupy.random.randn` for full documentation,\n            :meth:`numpy.random.RandomState.randn`\n\n        \"\"\"\n        dtype = kwarg.pop('dtype', float)\n        if kwarg:\n            raise TypeError('randn() got unexpected keyword arguments %s'\n                            % ', '.join(kwarg.keys()))\n        return self.normal(size=size, dtype=dtype)\n\n    _1m_kernel = elementwise.ElementwiseKernel(\n        '', 'T x', 'x = 1 - x', 'cupy_random_1_minus_x')\n\n    def random_sample(self, size=None, dtype=float):\n        \"\"\"Returns an array of random values over the interval ``[0, 1)``.\n\n        .. seealso::\n            :func:`cupy.random.random_sample` for full documentation,\n            :meth:`numpy.random.RandomState.random_sample`\n\n        \"\"\"\n        dtype = _check_and_get_dtype(dtype)\n        size = _get_size(size)\n        out = cupy.empty(size, dtype=dtype)\n        if dtype.char == 'f':\n            func = curand.generateUniform\n        else:\n            func = curand.generateUniformDouble\n        func(self._generator, out.data.ptr, out.size)\n        RandomState._1m_kernel(out)\n        return out\n\n    def seed(self, seed=None):\n        \"\"\"Resets the state of the random number generator with a seed.\n\n        ..seealso::\n            :func:`cupy.random.seed` for full documentation,\n            :meth:`numpy.random.RandomState.seed`\n\n        \"\"\"\n        if seed is None:\n            try:\n                seed_str = binascii.hexlify(os.urandom(8))\n                seed = numpy.uint64(int(seed_str, 16))\n            except NotImplementedError:\n                seed = numpy.uint64(time.clock() * 1000000)\n        else:\n            seed = numpy.uint64(seed)\n\n        curand.setPseudoRandomGeneratorSeed(self._generator, seed)\n\n    def standard_normal(self, size=None, dtype=float):\n        \"\"\"Returns samples drawn from the standard normal distribution.\n\n        .. seealso::\n            :func:`cupy.random.standard_normal` for full documentation,\n            :meth:`numpy.random.RandomState.standard_normal`\n\n        \"\"\"\n        return self.normal(size=size, dtype=dtype)\n\n    def uniform(self, low=0.0, high=1.0, size=None, dtype=float):\n        \"\"\"Returns an array of uniformlly-distributed samples over an interval.\n\n        .. seealso::\n            :func:`cupy.random.uniform` for full documentation,\n            :meth:`numpy.random.RandomState.uniform`\n\n        \"\"\"\n        dtype = numpy.dtype(dtype)\n        size = _get_size(size)\n        rand = self.random_sample(size=size, dtype=dtype)\n        return dtype.type(low) + rand * dtype.type(high - low)\n\n\ndef seed(seed=None):\n    \"\"\"Resets the state of the random number generator with a seed.\n\n    This function resets the state of the global random number generator for\n    the current device. Be careful that generators for other devices are not\n    affected.\n\n    Args:\n        seed (None or int): Seed for the random number generator. If None, it\n            uses :func:`os.urandom` if available or :func:`time.clock`\n            otherwise. Note that this function does not support seeding by an\n            integer array.\n\n    \"\"\"\n    get_random_state().seed(seed)\n\n\n# CuPy specific functions\n\n_random_states = {}\n\n\n@atexit.register\ndef reset_states():\n    global _random_states\n    _random_states = {}\n\n\ndef get_random_state():\n    \"\"\"Gets the state of the random number generator for the current device.\n\n    If the state for the current device is not created yet, this function\n    creates a new one, initializes it, and stores it as the state for the\n    current device.\n\n    Returns:\n        RandomState: The state of the random number generator for the\n        device.\n\n    \"\"\"\n    global _random_states\n    dev = cuda.Device()\n    rs = _random_states.get(dev.id, None)\n    if rs is None:\n        rs = RandomState(os.getenv('CHAINER_SEED'))\n        _random_states[dev.id] = rs\n    return rs\n\n\ndef _get_size(size):\n    if size is None:\n        return ()\n    elif isinstance(size, collections.Sequence):\n        return tuple(size)\n    elif isinstance(size, int):\n        return size,\n    else:\n        raise ValueError('size should be None, collections.Sequence, or int')\n\n\ndef _check_and_get_dtype(dtype):\n    dtype = numpy.dtype(dtype)\n    if dtype.char not in ('f', 'd'):\n        raise TypeError('cupy.random only supports float32 and float64')\n    return dtype\n", "path": "cupy/random/generator.py"}]}