lisdude/toaststunt

random() - range doesn't allow negative numbers

Closed this issue · 1 comments

random(-5,5) -> INVARG.

This is undesired functionality, especially because c++ supports this just fine.

Likely just need to change bf_random to something like
`static package
bf_random(Var arglist, Byte next, void *vdata, Objid progr)
{
int nargs = arglist.v.list[0].v.num;

Num minnum = (nargs == 2 ? arglist.v.list[1].v.num : 1);
Num maxnum = (nargs >= 1 ? arglist.v.list[nargs].v.num : INTNUM_MAX);

free_var(arglist);

if (maxnum < minnum)
    return make_error_pack(E_INVARG);

std::uniform_int_distribution<Num> distribution(minnum, maxnum);
Var r = Var::new_int(distribution(rng));
return make_var_pack(r);

}`

I've created a PR to address this since I basically wrote the code already. :P