What is a thread-safe random number generator for perl?
问题 The core perl function rand() is not thread-safe, and I need random numbers in a threaded monte carlo simulation. I'm having trouble finding any notes in CPAN on the various random-number generators there as to which (if any) are thread-safe, and every google search I do keeps getting cluttered with C/C++/python/anything but perl. Any suggestions? 回答1: Do not use built-in rand for Monte Carlo on Windows. At least, try: my %r = map { rand() => undef } 1 .. 1_000_000; print scalar keys %r, "\n"