Compare commits

..

No commits in common. "3be557f95dbc706716b9a9947e41c1f2db92e251" and "93c2608c197c7e4843b19ca2e4dce33a12e146e1" have entirely different histories.

3 changed files with 7 additions and 19 deletions

View File

@ -18,7 +18,3 @@ missed = a['missed']
assert abs(existed - missed) < 10000
rnd = random.Random(7)
assert rnd.randint(1, 100) == 16
assert rnd.randint(1, 100) == 93
assert rnd.randint(1, 100) == 22

View File

@ -1,6 +1,6 @@
name: pocketpy
description: A lightweight Python interpreter for game engines. It supports Android/iOS/Windows/Linux/MacOS.
version: 2.0.3
version: 2.0.2
homepage: https://pocketpy.dev
repository: https://github.com/pocketpy/pocketpy

View File

@ -112,14 +112,12 @@ static uint64_t mt19937__next_uint64(mt19937* self) {
return (uint64_t)mt19937__next_uint32(self) << 32 | mt19937__next_uint32(self);
}
static double mt19937__random(mt19937* self) {
// from cpython
uint32_t a = mt19937__next_uint32(self) >> 5;
uint32_t b = mt19937__next_uint32(self) >> 6;
return (a * 67108864.0 + b) * (1.0 / 9007199254740992.0);
/* generates a random number on [0,1)-real-interval */
static float mt19937__random(mt19937* self) {
return mt19937__next_uint32(self) * (1.0 / 4294967296.0); /* divided by 2^32 */
}
static double mt19937__uniform(mt19937* self, double a, double b) {
static float mt19937__uniform(mt19937* self, float a, float b) {
if(a > b) { return b + mt19937__random(self) * (a - b); }
return a + mt19937__random(self) * (b - a);
}
@ -135,16 +133,10 @@ int64_t mt19937__randint(mt19937* self, int64_t a, int64_t b) {
}
static bool Random__new__(int argc, py_Ref argv) {
PY_CHECK_ARGC(1);
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);
return true;
}
static bool Random_seed(int argc, py_Ref argv) {