kippy33

08-27-2006, 04:23 PM

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?

View Full Version : Random Number Generating

kippy33

08-27-2006, 04:23 PM

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?

Philip M

08-27-2006, 07:08 PM

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);

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);

kippy33

08-27-2006, 10:05 PM

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

Philip M

08-28-2006, 07:56 AM

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?

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?

elfpickle

08-28-2006, 08:02 AM

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

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

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.