Hi, etj

Calling PDL->random is less unique among threads versus rand().

Edit: etj identified a race condition, hence less uniqueness.

use v5.030; use threads; use PDL; BEGIN { $PDL::no_clone_skip_warning = 1; } for my $id (1..4) { threads->create(sub { for (1..8000) { # my $r = CORE::rand(); my $r = PDL->random; say $r; } }); } $_->join for threads->list;

Thread CORE::rand()

$ perl test.pl | LC_ALL=C sort | uniq -c | sort -n | tail 1 0.9999196288117 1 0.999939390107826 1 1.52499260792638e-05 1 5.77532994405772e-05 1 6.39378495463916e-05 1 6.94432865593342e-05 1 7.17426768090945e-05 1 8.48674303988162e-05 1 9.10499814921195e-05 1 9.32151475616649e-05

Thread PDL->random

$ perl test.pl | LC_ALL=C sort | uniq -c | sort -n | tail 3 0.578372644755136 3 0.587725272162442 3 0.629117050685529 3 0.665209931957569 3 0.666012741533792 3 0.715907985301874 3 0.780440518879262 3 0.789289520984441 3 0.859969220981904 3 0.975280763021946

In reply to Re^5: PDL and srand puzzle - support added to MCE v1.891 by marioroy
in thread PDL and srand puzzle by syphilis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.