in reply to Re^2: string mutation script behaving erraticaly
in thread string mutation script behaving erraticaly

Oh, I see. Then maybe this can help you:
#!/usr/bin/perl use warnings; use strict; my %matrix; my @symbols = qw/A R N D C Q E G + H I L K M F P S T W + Y V/; my @table = (.9799, .0002, .0009, .0010, .0003, .0008, .0017, .0021, . +0002, .0006, .0004, .0002, .0006, .0002, .0022, .0035, .0032, .0000, +.0002, .0018, .0001, .9929, .0001, .0000, .0001, .0010, .0000, .0000, . +0010, .0003, .0001, .0019, .0004, .0001, .0004, .0006, .0001, .0008, +.0000, .0001, .0004, .0001, .9867, .0036, .0000, .0004, .0006, .0006, . +0021, .0003, .0001, .0013, .0000, .0001, .0002, .0020, .0009, .0001, +.0004, .0001, .0006, .0000, .0042, .9869, .0000, .0006, .0053, .0006, . +0004, .0001, .0000, .0003, .0000, .0000, .0001, .0005, .0003, .0000, +.0000, .0001, .0001, .0001, .0000, .0000, .9987, .0000, .0000, .0000, . +0001, .0001, .0000, .0000, .0000, .0000, .0001, .0005, .0001, .0000, +.0000, .0002, .0003, .0010, .0004, .0005, .0000, .9901, .0027, .0001, . +0024, .0001, .0003, .0006, .0004, .0000, .0006, .0002, .0002, .0000, +.0000, .0001, .0010, .0000, .0007, .0056, .0000, .0035, .9865, .0004, . +0002, .0003, .0001, .0004, .0001, .0000, .0003, .0004, .0002, .0000, +.0001, .0002, .0021, .0001, .0012, .0011, .0001, .0003, .0007, .9906, . +0001, .0000, .0001, .0002, .0001, .0001, .0003, .0021, .0003, .0000, +.0000, .0005, .0001, .0008, .0018, .0003, .0001, .0020, .0001, .0000, . +9933, .0000, .0001, .0001, .0000, .0002, .0003, .0001, .0001, .0001, +.0004, .0001, .0002, .0002, .0003, .0001, .0002, .0001, .0002, .0000, . +0000, .9915, .0009, .0002, .0012, .0007, .0000, .0001, .0007, .0000, +.0001, .0033, .0003, .0001, .0003, .0000, .0000, .0006, .0001, .0001, . +0004, .0022, .9871, .0002, .0045, .0013, .0003, .0001, .0003, .0004, +.0002, .0015, .0002, .0037, .0025, .0006, .0000, .0012, .0007, .0002, . +0002, .0004, .0001, .9858, .0020, .0000, .0003, .0008, .0011, .0000, +.0001, .0001, .0001, .0001, .0000, .0000, .0000, .0002, .0000, .0000, . +0000, .0005, .0009, .0005, .9968, .0001, .0000, .0001, .0002, .0000, +.0000, .0005, .0001, .0001, .0001, .0000, .0000, .0000, .0000, .0001, . +0002, .0008, .0006, .0000, .0004, .9944, .0000, .0000, .0001, .0003, +.0028, .0000, .0013, .0005, .0002, .0001, .0001, .0008, .0003, .0002, . +0005, .0001, .0002, .0002, .0001, .0001, .9935, .0012, .0004, .0000, +.0000, .0002, .0028, .0011, .0034, .0007, .0011, .0004, .0006, .0016, . +0002, .0002, .0001, .0007, .0004, .0003, .0017, .9800, .0038, .0005, +.0002, .0002, .0022, .0002, .0013, .0004, .0001, .0003, .0002, .0002, . +0001, .0011, .0002, .0008, .0006, .0001, .0005, .0032, .9874, .0000, +.0002, .0009, .0000, .0002, .0000, .0000, .0000, .0000, .0000, .0000, . +0000, .0000, .0000, .0000, .0000, .0001, .0000, .0001, .0000, .9995, +.0001, .0000, .0001, .0000, .0003, .0000, .0003, .0000, .0001, .0000, . +0004, .0001, .0001, .0000, .0000, .0021, .0000, .0001, .0001, .0002, +.9960, .0001, .0013, .0002, .0001, .0001, .0003, .0002, .0002, .0003, . +0003, .0057, .0011, .0001, .0017, .0001, .0003, .0002, .0010, .0000, +.0002, .9866); for my $column (@symbols) { for my $row (@symbols) { $matrix{$column}{$row} = shift @table; } } my $string; $string = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +; #$string = 'SVEQRISTDIGQAYQLQGLGSNLRSIRSKTGAGEVNYIDAAKSVNDNQLLAEIG'; print "$string\n"; print map mutate($_), split //, $string; print "\n"; sub mutate { my $char = shift; my $rand = rand; my $result = 0; while ($rand > 0 and $result <= @symbols) { $rand -= $matrix{$char}{$symbols[$result++]}; } return $symbols[$result - 1]; }
Update: bugfix.

Replies are listed 'Best First'.
Re^4: string mutation script behaving erraticaly
by zing (Beadle) on Jun 26, 2012 at 12:17 UTC
    Christ !!!! What a forum and what an overflow of response... U guys are superb.... Just thied the bugfix its working like charm. Keep up the good work everybody. Congratulations on living up to your forums name.