I need a pick-3 style javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jules

    #1

    I need a pick-3 style javascript

    I've searched high and low for a 3 digit number generator that will
    pick at random a number between 000 and 999.

    The only things I have found were generators that pick numbers from 0
    to 999.

    I want one that if the number picked is 0 through 99 it is generated
    as 000 through 099.

    Can anyone help me with this? Cause I'm stumpt.
  • Lee

    #2
    Re: I need a pick-3 style javascript

    Jules said:[color=blue]
    >
    >I've searched high and low for a 3 digit number generator that will
    >pick at random a number between 000 and 999.
    >
    >The only things I have found were generators that pick numbers from 0
    >to 999.
    >
    >I want one that if the number picked is 0 through 99 it is generated
    >as 000 through 099.
    >
    >Can anyone help me with this? Cause I'm stumpt.[/color]


    function pick3(){
    return ("00"+Math.floo r(Math.random() *1000)).substr(-3);
    }

    Comment

    • Guy Roydor

      #3
      Re: I need a pick-3 style javascript

      qqchose comme : prendre les 3 derniers caractères de
      ((Math.random + 1) * 1000 )

      Jules a écrit:[color=blue]
      > I've searched high and low for a 3 digit number generator that will
      > pick at random a number between 000 and 999.
      >
      > The only things I have found were generators that pick numbers from 0
      > to 999.
      >
      > I want one that if the number picked is 0 through 99 it is generated
      > as 000 through 099.
      >
      > Can anyone help me with this? Cause I'm stumpt.[/color]

      Comment

      • Dr John Stockton

        #4
        Re: I need a pick-3 style javascript

        JRS: In article <d798da97.04013 01342.39106b87@ posting.google. com>, seen
        in news:comp.lang. javascript, Jules <jhakie@yahoo.c om> posted at Fri, 30
        Jan 2004 13:42:18 :-
        [color=blue]
        >I've searched high and low for a 3 digit number generator that will
        >pick at random a number between 000 and 999.
        >
        >The only things I have found were generators that pick numbers from 0
        >to 999.
        >
        >I want one that if the number picked is 0 through 99 it is generated
        >as 000 through 099.[/color]

        A Number is a Number, a numeric value stored as an IEEE Double. What
        you are actually calling for is a String of three decimal digits.

        Obvious ways are

        function Random(N) { return Math.floor(N*(M ath.random()%1) ) } // in FAQ
        // but %1 : Opera

        /* 1 */ S = "" ; for (j=0 ; j<3 ; j++) S += Random(10)
        /* 2 */ S = String(1000+Ran dom(1000)).subs tring(1)

        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
        <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
        <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

        Comment

        Working...