Aside from using the System.Random inherent in the C# library, How would you transfer this properly (or the best way.) to C# in MVC4. System.Random seems far to clunky and burdensome because if the method gets called in short succession, the number doesn't become random.
The other problem I'm having is that the System.Random method requires a Min and a Max, if the Database that I'm going to be holding the Quotation strings in keeps growing, how to properly adjust for the size?
This is the original JavaScript code.
var which = Math.round(Math.random()*(Quotation.length - 1));
I'm trying to reproduce this JavaScript code to have better functionality by pulling from a model that can constantly be updated with new Quotation. I don't want to have to keep changing this code:
int ranNum;
Random random = new Random();
ranNum = random.Next(1,7);
every time the quotations increase... Right now, it's going to list any of the 7 Quotation Strings, but if the Database increases in Quotation from 7 to 9, I'll have to go back and change the 7 to a 9, and so on and so forth. This is tedious, There has to be a better way.
Here is the original JavaScript code:
<script language="JavaScript">
function rotateEvery(sec)
{
var Quotation=new Array()
// QUOTATIONS
Quotation[0] = '<p>A journey of a thousand li begins with a single step.</p> Confucian Proverb.';
Quotation[1] = '<p>A picture is worth a thousand words.</p> Confucian Proverb.';
Quotation[2] = '<p>After all I have no nationality and am not anxious to claim any. Individuality is more than nationality.</p> Confucian Proverb.';
Quotation[3] = '<p>Be not ashamed of mistakes and thus make them crimes.</p> Confucian Proverb.';
Quotation[4] = '<p>He who counsels himself, counsels a fool.</p> Confucian Proverb.';
Quotation[5] = '<p>If thy strength will serve, go forward in the ranks; if not, stand still.</p> Confucian Proverb.';
Quotation[6] = '<p>Train equally the mind and body.</p> Confucian Proverb.';
var which = Math.round(Math.random()*(Quotation.length - 1));
document.getElementById('textrotator').innerHTML = Quotation[which];
setTimeout('rotateEvery('+sec+')', sec*1000);
}
</script>
Thank you in advance.