var r_text = new Array (); r_text = "All the leaves are brown"; r_text = "And the sky is grey"; r_text = "I've been for a walk"; r_text = "On a winter's day"; r_text = "I'd be safe and warm"; r_text = "If I was in L.A."; r_text = "California dreaming, On such a winter's day";
var i = Math.random();
The variable i now contains a floating point (decimal) number between 0 and 1. We have to convert it to an integer between 0 to 6 so that it can be used as an index to retrieve the string from the r_text array.
i = 7 * i; i = Math.floor(i);
We multiply the random floating point number (whose value is between 0.0 and 1.0) by 7 so that we get a number (again a floating point) that ranges from 0.0 to 7.0. The Math.floor() is used to round down this number. Thus, 0.345… would result in 0 and 6.893.. would be floored to 6.
var i = Math.floor(7*Math.random())
The final step is to display the text through document.write() method.
We now place all this code between <script>-</script> tags.
In the past, I have displayed a random quote or a randomly selected a testimonial on the web page. And this is how I go about it.
The smartphone of today use 250,000 patents largest of any industry. [more...]