ID:2549144
 
Resolved
Compiler optimizations were causing pick(list) to fail with an incorrect "index out of bounds" error in some cases.
BYOND Version:512
Operating System:Windows 10 Pro 64-bit
Web Browser:Firefox 73.0
Applies to:Dream Daemon
Status: Resolved (513.1514)

This issue has been resolved.
Descriptive Problem Summary:
In some cases the implemented Mersenne Twister RNG will return an invalid value of 1 in the RandDouble function, which can cause runtime errors in other functions that utilize it.

Numbered Steps to Reproduce Problem:
Run the below snippet anywhere and a runtime out of bounds error will happen on the last pick outside the loop.

Code Snippet (if applicable) to Reproduce Problem:
var/list/stuff = list(1,2,3,4,5)
rand_seed(48)
for(var/i in 1 to 245380)
var/p = pick(stuff)

var/p = pick(stuff) // runtime

Expected Results:
Expected values for the generator would be in the interval [0,1). Expected result for the code snippet would be no runtime errors.

Actual Results:
Actual values the generator can return are in the interval [0,1]. Actual result from the snippet is an unexpected runtime error.

Workarounds:
Use pick in a try-catch block and when it captures an OOB error retry the pick again.
Lummox JR resolved issue with message:
Compiler optimizations were causing pick(list) to fail with an incorrect "index out of bounds" error in some cases.
RandDouble() was not returning 1, but I suspect the math done on it was being warped by the compiler. I'm still using RandDouble() unaltered in the fixed version.