.
Results 1 to 6 of 6

Thread: Portal-generated trains: are they really random?

  1. #1
    Join Date
    Nov 2006
    Location
    stuck in Folsom Prison, and time keeps draggin' on...
    Posts
    1,470
     

    Default Portal-generated trains: are they really random?

    Hello folks,

    I am beginning to have some doubt about the actual randomness of train generation from portals. I noticed some portal-generated trains appear much often than others that are very rarely seen, so I took some notes while testing a session.

    The session uses 4 portals (actually, trackmarks configured as portals using the "Un-portal" rule) to generate random freight trains. Portal 1 has a 6-consist list, Portal 2 has a 7-consist list, Portals 3 & 4 have a 4-consist list.

    NOTE: A friend of mine has noticed the same behaviour - even though he has not recorded it - when using the "Un-portal 2" rule. We do not know it this issue also applies to other portal types (e.g. the standard Auran built-in portals), but we think - maybe wrongly - the random selection process used is the same.

    These are the data I collected after 40 tests:

    Portal #1 Generated Actual % Expected % Actual/Expected
    Train #1 15 37,5% 16,7% 225%
    Train #2 3 7,5% 16,7% 45%
    Train #3 5 12,5% 16,7% 75%
    Train #4 4 10,0% 16,7% 60%
    Train #5 4 10,0% 16,7% 60%
    Train #6 9 22,5% 16,7% 135%
    40
    Portal #2
    Train #1 11 28% 14,3% 193%
    Train #2 3 8% 14,3% 53%
    Train #3 5 13% 14,3% 88%
    Train #4 2 5% 14,3% 35%
    Train #5 6 15% 14,3% 105%
    Train #6 5 13% 14,3% 88%
    Train #7 8 20% 14,3% 140%
    40
    Portal #3
    Train #1 18 45% 25,0% 180%
    Train #2 5 13% 25,0% 50%
    Train #3 6 15% 25,0% 60%
    Train #4 11 28% 25,0% 110%
    40
    Portal #4
    Train #1 19 48% 25,0% 190%
    Train #2 4 10% 25,0% 40%
    Train #3 7 18% 25,0% 70%
    Train #4 10 25% 25,0% 100%
    40

    As you can see, in all portals Train #1 is generated much often than expected: 180% to 225%; the same could also be true - to a lesser extent - for the last train (100% to 140%).

    Is this effect inevitable - and associated with the way computers generate random variables - or there are ways to obtain uniformly distributed random results?

    Thanks in advance.
    Carlo "Pendolino" - TrainZItalia PRO Administrator

    UP fan 5,000 miles away from the nearest UP tracks

  2. #2

    Default

    A large majority of contents creators relies on a standard random function in their script Math.Rand(int lowValue, int UpperValue) which should return a number between the low value and the upper value with uniformly distributed results. And I don't think many creators have checked if the results are effectively uniformly distributed or not. And as this standard random function is generally derived from a similar function available in the system library of the computer used, we are generally totally dependent of the computer manufacturer implementation ...

    There are a lot of other methods to write from scratch some random number generator, but that is a lot of work to implement and also a lot of script time consumed for that and I don't think many creators are ready to reinvent the wheel only to have better uniform random distribution ...

    But that's only my opinion.
    Regards.
    Pierre.

  3. #3
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    2,007
     

    Default

    Hi

    I too have noticed that the random distribution using Un-Portal 2 doesn't appear to be particularly random although I haven't kept records. Looking at your results above it strikes me that this could be used to advantage in some situations. As you have pointed out that the first and last entries produce most consists then, on a predominately coal route such as EK3 for example, it would make sense to use the first and last slots for coal trains and the other slots for consists that would appear less frequently.

    I use Un-Portal 2 to generate random AI background traffic on a route in a coal producing area so I will reload the portals in accordance with your findings and see what happens.

    Regards

    Brian

  4. #4
    Join Date
    Nov 2006
    Location
    stuck in Folsom Prison, and time keeps draggin' on...
    Posts
    1,470
     

    Default

    Thanks for the replies.

    @pguy:

    I'm almost illitterate as regards to scripting: do you mean that the distribution of random-generated values may change depending on the PC on which the script is run?

    @Kennilworth:

    As the saying goes, "When life gives you lemons, make lemonade" . I agree with your idea of using slot #1 for the most common train running on a given line.

    Iam still collecting data for the purpose of formulating some empirical "law", so as to be able to reasonably predict which trains will be spawned. So far, I'm reasonably certain that, for a portal spawning X trains, the probability of having Train #1 spawned is 2 times 1/X.

    In my example, Portals #1 and #2 are located near a port and an intermodal terminal: I set both of them so that Train #1 is a ballast train and the remainder are container trains, with a few grain hopper trains. I thought I will mostly see colourful freights, but what I got is an endless parade of ballast trains .

    Regards
    Carlo "Pendolino" - TrainZItalia PRO Administrator

    UP fan 5,000 miles away from the nearest UP tracks

  5. #5
    Join Date
    Nov 2006
    Location
    United States of America, Massachusetts, Haverhill
    Posts
    25,202
     

    Default

    Very interesting little study there, Carlo. I wonder too if the randomness isn't quite as random as it should be because the numbered range is so small. If we had a pool of hundreds of consists, then I would think the values maybe a bit more widespread.

    I do like Brian's use of coal consists. I can see that being very helpful on the EKV which I have integrated into a much larger and more complex operation where empties are a bit of a problem.

    John
    John
    Trainz User Since: 12-2003
    Trainz User ID: 124863
    T:ANE Build: 94829
    TRS2019: 98592

  6. #6
    Join Date
    Nov 2006
    Location
    stuck in Folsom Prison, and time keeps draggin' on...
    Posts
    1,470
     

    Default

    Hello John,

    I have not fully understood what do you mean when you wrote "If we had a pool of hundreds of consists, then I would think the values maybe a bit more widespread."? Having one hundred different consists listed for a single portal, or monitoring hundreds of emitted consists?

    Since yesterday, I have taken 10 more samples, and the frequencies appear to be more or less constant. I will take more: if this is only a statistical anomaly, it should disappear as the number or samples increases (maybe ).

    Regards
    Carlo "Pendolino" - TrainZItalia PRO Administrator

    UP fan 5,000 miles away from the nearest UP tracks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •