1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 PyDoc_STRVAR(_random_Random_random__doc__,
6 "random($self, /)\n"
7 "--\n"
8 "\n"
9 "random() -> x in the interval [0, 1).");
10
11 #define _RANDOM_RANDOM_RANDOM_METHODDEF \
12 {"random", (PyCFunction)_random_Random_random, METH_NOARGS, _random_Random_random__doc__},
13
14 static PyObject *
15 _random_Random_random_impl(RandomObject *self);
16
17 static PyObject *
_random_Random_random(RandomObject * self,PyObject * Py_UNUSED (ignored))18 _random_Random_random(RandomObject *self, PyObject *Py_UNUSED(ignored))
19 {
20 return _random_Random_random_impl(self);
21 }
22
23 PyDoc_STRVAR(_random_Random_seed__doc__,
24 "seed($self, n=None, /)\n"
25 "--\n"
26 "\n"
27 "seed([n]) -> None.\n"
28 "\n"
29 "Defaults to use urandom and falls back to a combination\n"
30 "of the current time and the process identifier.");
31
32 #define _RANDOM_RANDOM_SEED_METHODDEF \
33 {"seed", (PyCFunction)(void(*)(void))_random_Random_seed, METH_FASTCALL, _random_Random_seed__doc__},
34
35 static PyObject *
36 _random_Random_seed_impl(RandomObject *self, PyObject *n);
37
38 static PyObject *
_random_Random_seed(RandomObject * self,PyObject * const * args,Py_ssize_t nargs)39 _random_Random_seed(RandomObject *self, PyObject *const *args, Py_ssize_t nargs)
40 {
41 PyObject *return_value = NULL;
42 PyObject *n = Py_None;
43
44 if (!_PyArg_CheckPositional("seed", nargs, 0, 1)) {
45 goto exit;
46 }
47 if (nargs < 1) {
48 goto skip_optional;
49 }
50 n = args[0];
51 skip_optional:
52 return_value = _random_Random_seed_impl(self, n);
53
54 exit:
55 return return_value;
56 }
57
58 PyDoc_STRVAR(_random_Random_getstate__doc__,
59 "getstate($self, /)\n"
60 "--\n"
61 "\n"
62 "getstate() -> tuple containing the current state.");
63
64 #define _RANDOM_RANDOM_GETSTATE_METHODDEF \
65 {"getstate", (PyCFunction)_random_Random_getstate, METH_NOARGS, _random_Random_getstate__doc__},
66
67 static PyObject *
68 _random_Random_getstate_impl(RandomObject *self);
69
70 static PyObject *
_random_Random_getstate(RandomObject * self,PyObject * Py_UNUSED (ignored))71 _random_Random_getstate(RandomObject *self, PyObject *Py_UNUSED(ignored))
72 {
73 return _random_Random_getstate_impl(self);
74 }
75
76 PyDoc_STRVAR(_random_Random_setstate__doc__,
77 "setstate($self, state, /)\n"
78 "--\n"
79 "\n"
80 "setstate(state) -> None. Restores generator state.");
81
82 #define _RANDOM_RANDOM_SETSTATE_METHODDEF \
83 {"setstate", (PyCFunction)_random_Random_setstate, METH_O, _random_Random_setstate__doc__},
84
85 PyDoc_STRVAR(_random_Random_getrandbits__doc__,
86 "getrandbits($self, k, /)\n"
87 "--\n"
88 "\n"
89 "getrandbits(k) -> x. Generates an int with k random bits.");
90
91 #define _RANDOM_RANDOM_GETRANDBITS_METHODDEF \
92 {"getrandbits", (PyCFunction)_random_Random_getrandbits, METH_O, _random_Random_getrandbits__doc__},
93
94 static PyObject *
95 _random_Random_getrandbits_impl(RandomObject *self, int k);
96
97 static PyObject *
_random_Random_getrandbits(RandomObject * self,PyObject * arg)98 _random_Random_getrandbits(RandomObject *self, PyObject *arg)
99 {
100 PyObject *return_value = NULL;
101 int k;
102
103 if (PyFloat_Check(arg)) {
104 PyErr_SetString(PyExc_TypeError,
105 "integer argument expected, got float" );
106 goto exit;
107 }
108 k = _PyLong_AsInt(arg);
109 if (k == -1 && PyErr_Occurred()) {
110 goto exit;
111 }
112 return_value = _random_Random_getrandbits_impl(self, k);
113
114 exit:
115 return return_value;
116 }
117 /*[clinic end generated code: output=a7feb0c9c8d1b627 input=a9049054013a1b77]*/
118