_randommodule.c.h 3.0 KB

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