Interesting observation on pathnode selection

Discussions about Coding and Scripting

Interesting observation on pathnode selection

Postby JackGriffin » Sun Oct 14, 2018 5:47 am

The last few days I'm using this:
Code: Select all
   NavPoint = Rand(NumPoints);

to find 5 random pathnodes throughout the level. To my surprise it has a real tendency to select either the same node or one very close to it many more times than pure chance would allow. Is this something you have seen in anything you've done? I don't see where I could have introduced selection bias into the code anywhere but something is for sure slanting things away from random.
"You damn kids, back in my time we made the items, maps and games ourselves with an unwieldy engine using counter-intuitive crash-prone tools and we liked it so much we built communities around this which nowadays look like cults because they're quasi-parallel societies based on the same old games." -Hellkeeper
User avatar
JackGriffin
Godlike
 
Posts: 3758
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: Hack coder

Re: Interesting observation on pathnode selection

Postby sektor2111 » Sun Oct 14, 2018 10:26 am

Did you try
Code: Select all
   NavPoint = int(RandRange(0,NumPoints));
?
User avatar
sektor2111
Godlike
 
Posts: 3959
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Interesting observation on pathnode selection

Postby JackGriffin » Sun Oct 14, 2018 3:11 pm

I just don't know if this is confirmation bias or not but that seemed to fix it. After a few tests the selected spots seem much more random. Thanks Nels.
"You damn kids, back in my time we made the items, maps and games ourselves with an unwieldy engine using counter-intuitive crash-prone tools and we liked it so much we built communities around this which nowadays look like cults because they're quasi-parallel societies based on the same old games." -Hellkeeper
User avatar
JackGriffin
Godlike
 
Posts: 3758
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: Hack coder

Re: Interesting observation on pathnode selection

Postby Feralidragon » Mon Oct 15, 2018 1:37 pm

I think that random-wise they should use the same algorithm and type of seeding, thus yielding similar results, although I don't really remember if the arguments are inclusive or exclusive, which may yield slightly biased results depending on such cases, since there would zero chance for the max value to ever be returned for exclusive ones.

For instance, I checked in the wiki (bear with me, been a while) and the Rand seems to be exclusive, meaning that it will return a random integer between 0 and Max-1, while RandRange seems to be inclusive, meaning that there's also a chance that it will return the Max value itself.

However it doesn't matter much what the wiki says, as this can easily be tested: create 2 integer arrays with 10 elements each for example, and run about 1000 iterations, with each iteration running a Rand and a RandRange, one for each array, between 0 and 10, and increment the value of the corresponding array index, then output the results to the log in the end.
This should clearly show if there's any biasing going on, and if the arguments are inclusive or exclusive.

Otherwise if you are expecting it to be inclusive and it's in fact exclusive, Max will never be returned, while if it's the other way around, and if you're using it for arrays (which sounds like it), it may result in a warning and malfunction of your code since it may end up returning Max after all which would correspond to non-existing array index.
User avatar
Feralidragon
Godlike
 
Posts: 5076
Joined: Wed Feb 27, 2008 6:24 pm
Location: Liandri
Personal rank: Work In Progress

Re: Interesting observation on pathnode selection

Postby JackGriffin » Mon Oct 15, 2018 2:50 pm

malfunction of your code

How dare you! Harumph!!

I did a bit of research and there are a few mentions of this from past years so I feel a bit better about it. I made great progress yesterday on my project so I kinda put this on the backburner but I'm for sure going to mod up a test and see if the bias is real or confirmation bias. I'll post back when I get the results.
"You damn kids, back in my time we made the items, maps and games ourselves with an unwieldy engine using counter-intuitive crash-prone tools and we liked it so much we built communities around this which nowadays look like cults because they're quasi-parallel societies based on the same old games." -Hellkeeper
User avatar
JackGriffin
Godlike
 
Posts: 3758
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: Hack coder

Re: Interesting observation on pathnode selection

Postby sektor2111 » Wed Oct 17, 2018 3:05 am

In current situation I don't see the problem in sorting last point because here is about number of PathNodes not about an array variable going over boundaries.
We might have the first, other 3 and even last. If mapper has figured a bad connected spot and added last PathNode into such a "Mid-Area" definitely sorting this Node is not a bad thing. Problem comes when cube-drawer has no clue about pathing and even has NONE PathNode as long as some others don't even know what are for those apples, no kidding here. That is the problem that has to be in account. Epic forgot to crash servers running crap without paths.
User avatar
sektor2111
Godlike
 
Posts: 3959
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.


Return to Coding, Scripting

Who is online

Users browsing this forum: Google [Bot] and 1 guest