- Forums
- Javascipt
- Generate Random Number In Javascript
The Page Will Show You Generate Random Number In Javascript Using A Simple Metho For Getting And Displaying A Random Number On Your Javascript Scripts [2208], Last Updated: Mon Jun 24, 2024
Webune Tutorials
Fri Jan 15, 2010
0 Comments
380 Visits
Webune Offers Excellent Web Hosting
if you are visiting us today its probably because you want to know how you can generate random numbers using javascript code.
well, if thats the case, then you are in luck because, Webune Web Hosting is going to show you what code to use. generating random text is easy by using the Math.random() function so for example i have this code:
var example = Math.random();
were you able to see the javascript alert message. if so, this is the code we use to make that script:
JAVASCRIPT CODE:
<script type="text/javascript" language="javascript">
var randText = new Array ();
randText[0] = "linux";
randText[1] = "windows";
randText[2] = "mac";
randText[3] = "UNIX";
var i = Math.floor(4*Math.random())
alert('This is a Random Generated Message:\n\nThe Random Number is ' +i+ ', and its value is ' + randText[i] );
</script>