patch by Yaron: Uses rand_s() from stdlib.h (when building for Windows)