Results 1 to 3 of 3

Thread: Generating a Random Number (JavaScript)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Wink

    Hi,

    I would like to know how to generate a random number between 1 and 3 using JavaScript. Could you please give me an example? Thanks
    rino_2
    Visual Basic, HTML
    Please Visit my Site: Richard's VB Site

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    here you are!
    Code:
    <SCRIPT LANGUAGE="JavaScript"><!--
    function myRnd(){
     
     return(Math.floor(Math.random() * 3)+1)
    
    };
    
     document.write(myRnd());
    
    </script>
    Mark
    -------------------

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Smile Thanks

    Thanks for the help Mark!
    rino_2
    Visual Basic, HTML
    Please Visit my Site: Richard's VB Site

Posting Permissions

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



Click Here to Expand Forum to Full Width