Results 1 to 5 of 5

Thread: Generate Random Numbers in JScript

  1. #1

    Thread Starter
    Addicted Member Frankie902's Avatar
    Join Date
    Feb 2001
    Location
    Lindenwold, NJ, USA
    Posts
    217

    Generate Random Numbers in JScript

    I want to make a random ad generator and I want it to generate a random number, and make someting like a select case in VB and put that html code into the browser
    Using:
    Visual Studio .Net Enterprise
    Visual Basic 6.0 Enterprise

  2. #2
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Use Math.random()
    Alcohol & calculus don't mix.
    Never drink & derive.

  3. #3

    Thread Starter
    Addicted Member Frankie902's Avatar
    Join Date
    Feb 2001
    Location
    Lindenwold, NJ, USA
    Posts
    217
    isnt that just 0 and a 1 randomized?
    Using:
    Visual Studio .Net Enterprise
    Visual Basic 6.0 Enterprise

  4. #4
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    Try this:

    function doRandom(){

    var intRand = Math.round((Math.random() * 2));

    switch(intRand){

    case 1:
    alert("1");
    break;
    case 2:
    alert("2");
    break;

    }//end switch

    }//end function

    Just multiply the upper range of the number that you want. If you want a number from 0 to 6 then use Math.random()*6. You have to round the number because Math.random() returns a number between 0.0 and 1.0 .


    Chris
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

  5. #5
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Yeah.

    x = minimum number;
    y = maximum number;
    randNum = (x + Math.random() * y)

    So, (1 + Math.random() * 100) would generate a number between 1 and 100.
    Alcohol & calculus don't mix.
    Never drink & derive.

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