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.