Improved random function. Now using rand_s(), if available.