if (!PyArg_ParseTuple(arg, "O:range", &m)) return (0);
if (PyInt_Check(m)) {
long mm = PyInt_AS_LONG(m);
- if (mm < 0)
- goto negative;
+ if (mm <= 0)
+ goto notpos;
if (mm <= 0xffffffff)
return (PyInt_FromLong(grand_range(GRAND_R(me), mm)));
}
if ((x = getmp(m)) == 0)
goto end;
- if (MP_NEGP(x))
- goto negative;
+ if (!MP_POSP(x))
+ goto notpos;
y = mprand_range(MP_NEW, x, GRAND_R(me), 0);
MP_DROP(x);
return (mp_pywrap(y));
-negative:
- TYERR("range must be nonnegative");
+notpos:
+ VALERR("range must be strictly positive");
end:
if (x) MP_DROP(x);
return (0);
static PyObject *grmeth_mp(PyObject *me, PyObject *arg, PyObject *kw)
{
size_t l;
- mpw o;
+ mpw o = 0;
char *kwlist[] = { "bits", "or", 0 };
if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&|O&:mp", kwlist,
convszt, &l, convmpw, &o))
goto end;
+ if (l < MPW_BITS && (o >> l)) VALERR("or mask too large");
return (mp_pywrap(mprand(MP_NEW, l, GRAND_R(me), o)));
end:
return (0);
METH (byte, "R.byte() -> BYTE")
METH (word, "R.word() -> WORD")
METH (block, "R.block(N) -> STRING")
- KWMETH(mp, "R.mp(bits, or = 0) -> MP")
+ KWMETH(mp, "R.mp(bits, [or = 0]) -> MP")
METH (range, "R.range(MAX) -> INT")
METH (mask, "R.mask(STR) -> STR")
METH (seedint, "R.seedint(I)")