I understood your recommendation to not call srandom inside threads. Basically, I'm reporting that PDL::random() results in lesser uniqueness versus CORE::rand(), regardless if calling srandom before spawning threads.
Edit: etj identified a race condition, hence less uniqueness.
use v5.030; use threads; use threads::shared; use PDL; BEGIN { $PDL::no_clone_skip_warning = 1; } my $lock : shared = 0; srandom(3); # PDL 2.089_01 for my $tid (1..16) { threads->create(sub { my $output = ""; for (1..500000) { # my $r = CORE::rand(); my $r = PDL->random; $output .= "$r\n"; } lock $lock; print $output; }); } $_->join for threads->list;
CORE::rand()
$ perl test7.pl | wc -l 8000000 $ perl test7.pl | LC_ALL=C sort -u | wc -l 8000000 $ perl test7.pl | LC_ALL=C sort -u | wc -l 8000000 $ perl test7.pl | LC_ALL=C sort -u | wc -l 8000000
PDL->random
$ perl test7.pl | wc -l 8000000 $ perl test7.pl | LC_ALL=C sort -u | wc -l 7507936 $ perl test7.pl | LC_ALL=C sort -u | wc -l 7446785 $ perl test7.pl | LC_ALL=C sort -u | wc -l 7446785
In reply to Re^9: PDL and srand puzzle - uniqueness PDL->random vs CORE::rand
by marioroy
in thread PDL and srand puzzle
by syphilis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |