Randomly selecting a paragraph from Array list Javascript
<p>I am working on my own Lorem Ipsum generator, with the added bonus of generating the corresponding HTML formatting code in a box beside it.</p>

<p>So, the paragraph is generated via this button</p>

<p><code>&lt;button id="generate" type="button" onclick="LoremIpsumRandom()"&gt;1 Paragraph&lt;/button&gt;</code></p>

<p>and is generated here
    <code>&lt;p id="textarea"&gt;&lt;/p&gt;</code></p>

<pre><code>function LoremIpsumRandom()
{
    //global to store previous random int
     _oldInt = null;

var pickRandom = function(paragraphArray)
    {
        //random index of paragraphArray
        var randomInt = Math.floor(Math.random()*paragraphArray.length);
        //ensure random integer isn't the same as last
        if(randomInt == _oldInt)
            pickRandom(paragraphArray);
        else{
            _oldInt = randomInt;
            return paragraphArray[randomInt];
            }
    }
    //your lorem ipsum paragraphs
    var paragraphArray =     [
                            "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.", 
                            "Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.", 
                            "Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.", 
                            "Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur?", "Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?", 
                            "At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.", 
                            "Et harum quidem rerum facilis est et expedita distinctio.", "Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.", 
                            "Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae.", 
                            "Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."
                            ];  

//update element content (e.g. `&lt;div&gt;` with paragraph
    document.getElementById("textarea").innerHTML = pickRandom(paragraphArray);
    //document.getElementById("textarea-code").innerText = pickRandom("&amp;lt;P&amp;gt;" + (paragraphArray) + "&amp;lt;&amp;#47;P&amp;gt;");



}
</code></pre>

<p>No point including the CSS to be honest - it's just standard text boxes and auto-generated buttons.</p>

<p>So, the issue is that although I can generate the normal paragraph in the id="textarea" section, I want to be able to generate a raw HTML version as well (with the paragraph and line breaks code being shown.) So far, I've been able to generate the raw HTML with no issues, but when I added @pixelbobby 's section (which makes sure that when a sentence is selected, the next selection won't be the same, as true randomness can sometimes generate), the code doesn't work. In some instances, it's generated the raw HTML, but the generated paragraph is a different one.</p>

<p>The other functions (generating lists, multi-paragraphed sections and multi-levelled lists) utilise the raw HTML and output correctly, and it all runs smoothly. The raw HTML is always outputted to 
<code>&lt;p id="textarea-code"&gt;&lt;/p&gt;</code>
which is next to the first textarea section.</p>

<p>Can someone tell me how I can modify the script so that the raw HTML part of the script generates the same paragraph as the result of the <code>pickRandom(paragraphArray)</code></p>

<p>So,
This - <code>document.getElementById("textarea-code").innerText = pickRandom("&amp;lt;P&amp;gt;" + (paragraphArray) + "&amp;lt;&amp;#47;P&amp;gt;");</code>
needs to be the same as - <code>document.getElementById("textarea").innerHTML = pickRandom(paragraphArray);</code>
but with the raw HTML specified in the pickRandom() part of the line.</p>

<p>Can anyone help?</p>

<p>Thanks :)</p>
