How to use "Math.random()" to generate a random number in JavaScript? I have started doing the coding in JavaScript programs some months ago. Now I can make a better programs in JavaScript. The problem I am facing now is while using the Math.random(). Can anyone explain me how to use "Math.random()" to generate a random number..?? I have tried a lot of different things but was not successful. The sample of coding will be appreciable. Expecting some help as soon as possible.! 
Re: How to use "Math.random()" to generate a random number in JavaScript? If you want to generate a random number between 1 and 200, you can do this by using the random() method. Use the following code for better explanation : Code: var rand_no = Math.random(); 
Re: How to use "Math.random()" to generate a random number in JavaScript? I would like to suggest you to use the JavaScript ceil() method. By using this method, you can round a decimal number to the next higher integer. Check the following example that demonstrates the same : Quote:

Re: How to use "Math.random()" to generate a random number in JavaScript? While creating the applications in JavaScript like dice, random image script, or random link generator, a random number plays an important role. If you want to generate a random number in JavaScript, you can use the mentioned code : Code: var randomnumber=Math.floor(Math.random()*101) 
Re: How to use "Math.random()" to generate a random number in JavaScript? Whenever you need a random number, you can use the "Math.random()" every time. Also the main thing in Math.random() is that you have to set the range. Check the following example where I have used it. Code: now = new Date(); 
Re: How to use "Math.random()" to generate a random number in JavaScript? If you want to generate the random numbers from a given range, follow the steps for that :
Code: var rand_no = Math.floor((209)*Math.random()) + 10; 
All times are GMT +5.5. The time now is 01:09 PM. 