Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post 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?

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,027
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    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);

  • #3
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How would I set the input box to be X, and set the submit button to generate the numbers?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,027
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    Quote 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?

  • #5
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    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
    Last edited by elfpickle; 08-28-2006 at 08:13 AM.


  •  

    Posting Permissions

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