mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 08:44:20 +03:00
Поддержка Long в std::rand
This commit is contained in:
parent
1bcbe1978a
commit
00e4e9cb39
@ -16,6 +16,20 @@ public final class std_rand implements Function {
|
||||
Arguments.checkRange(0, 2, args.length);
|
||||
if (args.length == 0) return NumberValue.of(RND.nextDouble());
|
||||
|
||||
final Object raw = args[0].raw();
|
||||
if (raw instanceof Long) {
|
||||
long from = 0L;
|
||||
long to = 100L;
|
||||
if (args.length == 1) {
|
||||
to = (long) raw;
|
||||
} else if (args.length == 2) {
|
||||
from = (long) raw;
|
||||
to = ((NumberValue) args[1]).asLong();
|
||||
}
|
||||
final long randomLong = RND.nextLong() >>> 1;
|
||||
return NumberValue.of(randomLong % (to - from) + from);
|
||||
}
|
||||
|
||||
int from = 0;
|
||||
int to = 100;
|
||||
if (args.length == 1) {
|
||||
|
Loading…
Reference in New Issue
Block a user