I am trying to generate random strings from a set string with all of them being the same length and can be found already present inside the known string.

my $DNA = "AACCGTTAATGGGCATCGATGCTATGCGAGCT"; $DNA_length = length($DNA); my $random_sequence = &random_sequence($DNA); my $random_position = &random_position($DNA_length); my $random_base = &mutate(); $DNA[$random_sequence] = $DNA; my @DNA_array = split("", $DNA); print "$random_position\t$random_base\n"; $DNA_array[$random_position] = $random_base; print join("", @DNA_array), "\n"; sub random_sequence { my $sequence = m/\w*[ACTG]{5}*/; my $new_sequence = int(rand(scalar $sequence) return $sequence[$new_sequence]; sub random_position { my ($seed) = @_; return int(rand($seed)); } sub mutate { my @base_array = ('A','C','G','T'); my $random_base = int(rand(scalar @base_array)); return $base_array[$random_base]; }

I can get the random replacement but i cannot get the random sequence that the replacement is supposed to occur in. I have searched for a similar problem but none that I found helped solve the problem.


In reply to Generating mulitple random strings of a set length by Kajed

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.