Interesting observation on pathnode selection

Discussions about Coding and Scripting
Post Reply
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Interesting observation on pathnode selection

Post by JackGriffin »

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.
So long, and thanks for all the fish
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Interesting observation on pathnode selection

Post by sektor2111 »

Did you try

Code: Select all

   NavPoint = int(RandRange(0,NumPoints));
?
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Interesting observation on pathnode selection

Post by JackGriffin »

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.
So long, and thanks for all the fish
User avatar
Feralidragon
Godlike
Posts: 5489
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Interesting observation on pathnode selection

Post by Feralidragon »

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.
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Interesting observation on pathnode selection

Post by JackGriffin »

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.
So long, and thanks for all the fish
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Interesting observation on pathnode selection

Post by sektor2111 »

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.
Post Reply