mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
fix random.seed
This commit is contained in:
parent
abf96a7128
commit
8d5cd7c1b8
@ -159,10 +159,15 @@ static bool Random__init__(int argc, py_Ref argv) {
|
|||||||
|
|
||||||
static bool Random_seed(int argc, py_Ref argv) {
|
static bool Random_seed(int argc, py_Ref argv) {
|
||||||
PY_CHECK_ARGC(2);
|
PY_CHECK_ARGC(2);
|
||||||
PY_CHECK_ARG_TYPE(1, tp_int);
|
|
||||||
mt19937* ud = py_touserdata(py_arg(0));
|
mt19937* ud = py_touserdata(py_arg(0));
|
||||||
py_i64 seed = py_toint(py_arg(1));
|
py_i64 seed;
|
||||||
mt19937__seed(ud, seed);
|
if(py_isnone(&argv[1])) {
|
||||||
|
seed = time_ns();
|
||||||
|
} else {
|
||||||
|
PY_CHECK_ARG_TYPE(1, tp_int);
|
||||||
|
seed = py_toint(py_arg(1));
|
||||||
|
}
|
||||||
|
mt19937__seed(ud, (uint32_t)seed);
|
||||||
py_newnone(py_retval());
|
py_newnone(py_retval());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user