JavaScript function that Randomly replaces x percent of Letters
<p>I need a JavaScript function that goes through all of the elements of a page that belong to a specific class and replace at random 'X' percent of the characters. The idea is to obscure the message by varying degree.  The more obscure the message, the more challenging it is to decipher.  </p>

<p>I just started by attempting a single element with getElementById, but got stuck there already with the line *s[i]='_';* . In addition to this problem of replacing a specific character, I actually need to perform the function on every paragraph that belongs to the member of a specific class... not just one single id element.</p>

<p>Edit: There is a problem with my approach: special characters like &amp;amp; . However, this is a minor issue for my use, and I can accept that to get started.</p>

<pre><code>&lt;!DOCTYPE html&gt; 
&lt;html lang="en"&gt; 
&lt;head&gt; 
    &lt;script type="text/javascript"&gt;
        function obscure(percent){
            var s = document.getElementById('change').innerHTML;
            var i;
            for(i=0; i&lt;s.length;i++){
                 //return a random integer between 0 and 100
                 var rand = Math.floor(Math.random()*(percent+1)));
                     if(rand &lt; percent){
                         s[i]='_';
                     }
            }
            document.getElementById('change').innerHTML = s;
        }
    &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;a onclick="obscure(50)"&gt;obscure&lt;/a&gt;
    &lt;p id="change"&gt;
        To be, or not to be: that is the question:
        Whether 'tis nobler ...
    &lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
