Hi
For previous information, see the "Donner Pass scenario 5] Grade crossing (bad weather)" thread.
I put on my thinking cap and came to the conclusion that as written, the FailRange value returned is always 2000 - it is not a range. The lua file calculation appears to create a random number that is perhaps in the range of 1-2000 then it's divided by 2000. If this is the case, the number returned from the EngineScript is meaningless and has no effect on the value of the testing of the random number. Am I correct in this assumption? I need someone who knows how both the math.random function and how the math in the lua script works to reply.
The lua script now checks the result and if greater than 0.95 fails the engine. These tests are set to occur once each 60 seconds so if the engine uses these calculations, the odds are ~5 in 100 or ~1 in 20 that it will fail in any particular minute.
What I'm thinking is to change the lua script so the odds become an actual 1-FailRange chance of failure. I think I am correct if I take a random number in the 0-1 range, multiply it by the FailRange (in this case 2000) then test for a result of less than 1 to get a 1 in 2000 odds result. Because there is not a division being done, a zero random number shouldn't cause a failure. Again, I need someone who knows to let me know how the rewrite of the lua script should be done to accomplish this.
Thanks,
GaryG