0-indexed vs 1-indexed

New releases and general discussions.

Post » Sat Feb 21, 2009 4:53 pm

I think I suggested it to Ashley at some point, but it makes more sense to clear it up now than after beta :).
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Sat Feb 21, 2009 8:46 pm

Then I propose

random(N) returns 1 to N

and random(A, B) would return any number from A to B inclusive (so random(1, N) is the same as random(N)).

This means any cases of random(N) that currently exist must be changed to random(0, N-1). This will break a lot of things, but (hopefully) Construct will only grow more in future, so the least damaging time to do this is definitely now.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sat Feb 21, 2009 10:53 pm

I think you should just keep the random function the same. I have quite a few things that would be half-broken. :?
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Sat Feb 21, 2009 11:15 pm

[quote="linkman2004":mvx2vehs]I think you should just keep the random function the same. I have quite a few things that would be half-broken. :?[/quote:mvx2vehs]

Your noble sacrifice is for the greater good. Waver not, and face your fate though it may be grim... for yours is the glorious death of a warrior.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sat Feb 21, 2009 11:43 pm

[quote="deadeye":2kvomt5t][quote="linkman2004":2kvomt5t]I think you should just keep the random function the same. I have quite a few things that would be half-broken. :?[/quote:2kvomt5t]

Your noble sacrifice is for the greater good. Waver not, and face your fate though it may be grim... for yours is the glorious death of a warrior.[/quote:2kvomt5t]

yeah, i agree. i`ll sacrifice my projects to... but besides it`s almost imposible to finish big game in construct in its current state, so it`s better to prepare matterials and ideas while waiting for 1.0.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
71
S
19
G
19
Posts: 1,919
Reputation: 16,910

Post » Sun Feb 22, 2009 1:08 am

i would not mind having to dump old event sheets, either. there's no place for sentimental backwards compatibility at this time :)

but i do worry about the changed behavior. by deviating from the 'norm', you do not only make it harder for people with (even small) experiences in other languages to adjust to construct, but also to allow beginners who've learned construct to jump into other pools. i also doubt that indexing is a much easier task for beginners in a 1-indexed environment ...

now don't get the impression that i'm zealously opinionated about this point, i'd just like to contribute to the discussion :) as long as it gets documented somewhere, this won't kill me... immediately.
B
2
S
2
G
4
Posts: 171
Reputation: 1,792

Post » Sun Feb 22, 2009 4:36 pm

Or leave random the way it is and explain in the program (by extra info, displayed when clicked on it, for example) that it starts at 0.
(and perhaps redirect to the wiki to explain and give examples why)

Either way I personally don't mind random starting at 0 or 1, at this moment.

Scirra's new slogan will be: Random starts at 0, deal with it.
B
16
S
5
G
7
Posts: 599
Reputation: 5,000

Post » Sun Feb 22, 2009 6:33 pm

Yeah, but the fact is that there are so few reasons to have it start with zero, and so many to have it start with one.
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Sun Feb 22, 2009 10:20 pm

What about negative values in the Random() function? Would Random(-10, 10) work?

Also, what would happen if you put a higher number first, i.e. Random(10, 1)?

Just curious.
B
2
S
2
G
3
Posts: 105
Reputation: 1,510

Post » Mon Feb 23, 2009 7:33 am

In all cases we can offset it with an addition... like -10+Random(11) would range from -10 to 10. But Random in its current form is confusing; one expects that the N will be included (11). Also, one would also expect that Random (1) would give boolean results (0 for false, 1 for true), but in fact you have to do Random(2) (gives 0 or 1).

Changing it to 1-indexed could also cause confusion; Random(2) would return 1 or 2, but not 0. Those used to the zero could easily get confused.

What I say is, decide on a convention and stick to it! Also explain it well in tooltip and in documentation.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

PreviousNext

Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 5 guests