Neither is considering the affect it has on the randomness of the result

Well, actually it is!

Given the $size of the test, the probability of salva2 generating a string starting by two equal characters is 1/($size+1) instead of the 1/$size in the other methods.

The funny thing is that salva2 is unbiased, they are the other methods that are actually biased!!!

The following code counts the number of repetitions at any given position in the generated strings:

@set = (1..3); $max_reps = 2; $len = 10; my @acu = ([], []); my @gen = (\&gen_salva, \&gen_salva2); my ($total, $ds) = (0,0); my $n = 10000000; for (1..$n) { for (0, 1) { my $out = $gen[$_]->(); while ($out =~ /(.)\1/g) { $acu[$_]->[pos($out) - 2]++; } } } use Data::Dumper; print Dumper \@acu;
And this is the result:
salva => [ 3333044, 2222094, 2591285, 2469706, 2509595, 2496496, 2501 +039, 2501529, 2497584 ] salva2 => [ 2500639, 2498220, 2499044, 2501878, 2500880, 2500962, 2498 +685, 2499675, 2508077 ]

So, with salva2 the probability of finding a repetition at any position is 1/($size+1) while with the rest of methods the probability varies between the maximum 1/$size (at position 0) and the minimum ($size-1)/$size**2 (at position 1).


In reply to Re^7: Random data generation. by salva
in thread Random data generation. by BrowserUk

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.