SRL Archive - FAQ

[BUG] RandomRange()


bg5

2015-04-02 08:29:08

RandomRange(Min,Max) gives number from Min to Max-1

e.x.


RandomRange(2,3);
will always return 2.

Kyle

2015-04-02 08:33:45

From: bg5
RandomRange(Min,Max) gives number from Min to Max-1

e.x.


RandomRange(2,3);
will always return 2.


I noticed that a little while ago. It seems that it is Min(Inclusive) to Max(Exclusive). I'm not sure if it's a bug or not, as some other languages I've seen do it the same way

Janilabo

2015-04-02 09:36:12

From: bg5
RandomRange(Min,Max) gives number from Min to Max-1

e.x.


RandomRange(2,3);
will always return 2.
Yeah it is not a bug, that is how it is supposed to work.. Take a look at here & here.

Totally would be a bit more logical, if the upper border would be reachable aswell - but that is just my 2 cents… :p

3Garrett3

2015-04-02 10:01:17

We talked about this on Skype before and I asked Wizzup about it.

The collective opinion of Skype was "It should be inclusive or exclusive on both the upper and the lower bounds, not inclusive on the lower bounds and exclusive on the upper bounds." This is especially true because I'm pretty sure 90% of us have been taught here that randomRange(x,y) is a random number between X and Y (inclusive).

The verdict on IRC was something like "Making it inclusive would break lots of things and isn't worth it."

bg5

2015-04-02 10:24:28

The collective opinion of Skype was "It should be inclusive or exclusive on both the upper and the lower bounds, not inclusive on the lower bounds and exclusive on the upper bounds."


Exactly, I was thinking the same. But it should be rathere inclusive, otherwise what RandomRange(2,3) (exclusive) was supposed to return?

"Making it inclusive would break lots of things"


or would fix a lot of unintelligible errors :P

3Garrett3

2015-04-02 10:29:45

From: bg5
Exactly, I was thinking the same. But it should be rathere inclusive, otherwise what RandomRange(2,3) (exclusive) was supposed to return?

or would fix a lot of unintelligible errors :P


Yeah I agree that inclusive on both bounds would be best. The general feeling was that it should be consistent at least because having inclusive/exclusive makes less sense intuitively.

I'm sure there were people who knew all along how this worked and some core features were probably written with this in mind. It would be a pain to make sure everything got changed.

slacky

2015-04-02 15:20:53

From: 3Garrett3
Yeah I agree that inclusive on both bounds would be best. The general feeling was that it should be consistent at least because having inclusive/exclusive makes less sense intuitively.

It acts the same as in FPC & Delphi.. Which is a good thing.. Else there could be confusion there, eg when people make plugins, port Delphi/FPC-code to Lape or similar stuff.

There is Random(lo,hi) which includes the upper bound..

3Garrett3

2015-04-02 17:28:16

From: slacky
It acts the same as in FPC & Delphi.. Which is a good thing.. Else there could be confusion there, eg when people make plugins, port Delphi/FPC-code to Lape or similar stuff.

There is Random(lo,hi) which includes the upper bound..


Wait, the Random(lo,hi)… is not the same as RandomRange(from, to)? Well if Random() is inclusive I'll just use that, doesn't bother me.

slacky

2015-04-02 20:10:26

From: 3Garrett3
Wait, the Random(lo,hi)… is not the same as RandomRange(from, to)? Well if Random() is inclusive I'll just use that, doesn't bother me.

Correct, Random is it's own function. Not an alias.

bg5

2015-04-03 17:25:32

From: slacky


There is Random(lo,hi) which includes the upper bound..


Good to know, I will use this one.