I'll start off by acknowledging that this is an odd question with a very limited scope of usage.

I've got a string, say, $_ = 'My name is Bob.'; I have an array @obs = (a..z);. I have a percentage $percentage='50%'. I want to obscure $percentage of $_ with characters from @obs in a uniform manner in that if I do it thirty times to the same string with the same percentage, I'll always get the same results. (By obscure I mean to substitute a (random) character with a random character from @obs).

My initial reaction to the problem was to use srand with a predetermined value, break up the string, pick quasirandomly which positions of the array to replace, pick a quasirandom value to replace it with, make the switch, then join the array back together. That just seems like a really clumsy manner with which to proceed, and including $percentage with such a short string made for some messy math.

I don't want to pollute other rand calls by defining srand, and all in all I think my process is clumsy at best. Any insight on how I might streamline this in a more efficient manner would be appreciated.

In reply to Obscuring a String by Anonymous Monk

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.