mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
fix a bug of random
This commit is contained in:
parent
069e80f2f5
commit
26a073de4f
@ -137,24 +137,19 @@ int64_t mt19937__randint(mt19937* self, int64_t a, int64_t b) {
|
||||
static bool Random__new__(int argc, py_Ref argv) {
|
||||
mt19937* ud = py_newobject(py_retval(), py_totype(argv), 0, sizeof(mt19937));
|
||||
mt19937__ctor(ud);
|
||||
if(argc == 1) return true;
|
||||
if(argc == 2) {
|
||||
PY_CHECK_ARG_TYPE(1, tp_int);
|
||||
py_i64 seed = py_toint(py_arg(1));
|
||||
mt19937__seed(ud, seed);
|
||||
return true;
|
||||
}
|
||||
return TypeError("Random(): expected 0 or 1 arguments, got %d", argc - 1);
|
||||
}
|
||||
|
||||
static bool Random__init__(int argc, py_Ref argv) {
|
||||
if(argc == 1) {
|
||||
// do nothing
|
||||
} else if(argc == 2) {
|
||||
mt19937* ud = py_touserdata(py_arg(0));
|
||||
if(!py_isnone(&argv[1])){
|
||||
PY_CHECK_ARG_TYPE(1, tp_int);
|
||||
py_i64 seed = py_toint(py_arg(1));
|
||||
mt19937__seed(ud, (uint32_t)seed);
|
||||
}
|
||||
} else {
|
||||
return TypeError("Random(): expected 1 or 2 arguments, got %d");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user