Skip to content

Commit 8905202

Browse files
committed
Merge pull request #1105 from xzyfer/fix/random-no-limit
Fix a couple issue with random()
2 parents ea8d033 + 3799d2e commit 8905202

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

functions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,16 +1071,16 @@ namespace Sass {
10711071
BUILT_IN(random)
10721072
{
10731073
Number* l = dynamic_cast<Number*>(env["$limit"]);
1074-
if (l && trunc(l->value()) != l->value()) error("argument $limit of `" + string(sig) + "` must be an integer", pstate);
10751074
if (l) {
1075+
if (trunc(l->value()) != l->value() || l->value() == 0) error("argument $limit of `" + string(sig) + "` must be a positive integer", pstate);
10761076
uniform_real_distribution<> distributor(1, l->value() + 1);
10771077
uint_fast32_t distributed = static_cast<uint_fast32_t>(distributor(rand));
10781078
return new (ctx.mem) Number(pstate, (double)distributed);
10791079
}
10801080
else {
10811081
uniform_real_distribution<> distributor(0, 1);
1082-
uint_fast32_t distributed = static_cast<uint_fast32_t>(distributor(rand));
1083-
return new (ctx.mem) Number(pstate, trunc(distributed));
1082+
double distributed = static_cast<double>(distributor(rand));
1083+
return new (ctx.mem) Number(pstate, distributed);
10841084
}
10851085
}
10861086

0 commit comments

Comments
 (0)