Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Random Number Generating

1. ## Random Number Generating

I run a random number generating service for a RPG message board I go to, and my website generates only numbers from 1-100. How could I script this so that the user can get random numbers between 1-X?

• var rand1 = Math.random();// generates a random number 0-.999999999999
var rand 2 = rand1 * x; // where x is the range desired, e.g. 250
var rand3= Math.ceil(rand3); // rounds the number up

or

var rand4 = Math.ceil(Math.random() * x);

• How would I set the input box to be X, and set the submit button to generate the numbers?

• Originally Posted by kippy33
How would I set the input box to be X, and set the submit button to generate the numbers?
Not sure what it is you are trying to achieve. This is the first time that input box and submit button have been mentioned.

Do you want to set the random number range, or does the user select it?
Please be a little clearer. What is the code you are using now?

• you must be new to this..

use the guy aboves math for random numbers but in the function

function makemerandom(numbax){

var rand1 = Math.random();// generates a random number 0-.999999999999
var rand2 = rand1 * numbax; // where x is the range desired, e.g. 250
var rand3= Math.ceil(rand3); // rounds the number up
document.all['yournumba'].value = rand2;

}

in your form add

<input id="yournumba" type="text" value="">
<input type="button" onclick="makemerandom(document.all['yournumba'].value)>

sorry about the stuffup.

so you enter the desired range into the input box and there you have it

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•