Whats wrong with this?

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

    #1

    Whats wrong with this?

    <script type="text/JavaScript" src="here.js">
    <!--
    function output() {
    var i = Math.round(5*Ma th.random());
    document.write( safetyTips[i]);
    }
    output();
    //-->
    </script>
    safetyTips[] - this array is in here.js ...

  • Evertjan.

    #2
    Re: Whats wrong with this?

    TheShadow1 wrote on 02 apr 2005 in comp.lang.javas cript:
    [color=blue]
    >
    <script type="text/JavaScript" src="here.js">
    > <!--
    > function output() {
    > var i = Math.round(5*Ma th.random());
    > document.write( safetyTips[i]);
    >}
    > output();
    > //-->
    > </script>
    >[/color]

    You cannot have both an external and inline scripting
    with the same <script> block.

    Don't use <!--, //-->, outdated for years.



    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)

    Comment

    • RobG

      #3
      Re: Whats wrong with this?

      TheShadow1 wrote:[color=blue]
      >
      <script type="text/JavaScript" src="here.js">
      > <!--
      > function output() {
      > var i = Math.round(5*Ma th.random());
      > document.write( safetyTips[i]);
      > }
      > output();
      > //-->
      > </script>
      >
      > safetyTips[] - this array is in here.js ...
      >[/color]

      Evertjan has already fixed your main problem, but you also have given
      yourself a maintenance problem by hard-coding (I presume) the length
      of your array.

      Given the general nature of the question in your subject, I'll add
      that you can also make it more concise (I've used 'sT' for the name
      of the safteyTips array to avoid wrapping):

      <script type="text/javascript" src="here.js"></script>
      <script type="text/javascript">
      document.write( sT[Math.round((sT. length-1)*Math.random( ))]);
      </script>

      is all that is required.

      --
      Rob

      Comment

      • Lee

        #4
        Re: Whats wrong with this?

        RobG said:[color=blue]
        >
        >TheShadow1 wrote:[color=green]
        >>
        <script type="text/JavaScript" src="here.js">
        >> <!--
        >> function output() {
        >> var i = Math.round(5*Ma th.random());
        >> document.write( safetyTips[i]);
        >> }
        >> output();
        >> //-->
        >> </script>
        >>
        >> safetyTips[] - this array is in here.js ...
        >>[/color]
        >
        > Evertjan has already fixed your main problem, but you also have given
        > yourself a maintenance problem by hard-coding (I presume) the length
        > of your array.
        >
        > Given the general nature of the question in your subject, I'll add
        > that you can also make it more concise (I've used 'sT' for the name
        > of the safteyTips array to avoid wrapping):
        >
        > <script type="text/javascript" src="here.js"></script>
        > <script type="text/javascript">
        > document.write( sT[Math.round((sT. length-1)*Math.random( ))]);[/color]

        Using Math.round() underselects the first and last elements of the array.
        sT[Math.floor(Math .random()*sT.le ngth)]

        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: Whats wrong with this?

          RobG <rgqld@iinet.ne t.auau> writes:
          [color=blue]
          > document.write( sT[Math.round((sT. length-1)*Math.random( ))]);[/color]
          ....[color=blue]
          > is all that is required.[/color]

          Don't use Math.round like this, it gives the first and last element
          only half the chance of the others.

          Use:

          sT[Math.floor(Math .random() * sT.length)]


          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • Mick White

            #6
            Re: Whats wrong with this?

            Lasse Reichstein Nielsen wrote:[color=blue]
            > RobG <rgqld@iinet.ne t.auau> writes:
            >
            >[color=green]
            >> document.write( sT[Math.round((sT. length-1)*Math.random( ))]);[/color]
            >
            > ...
            >[color=green]
            >> is all that is required.[/color]
            >
            >
            > Don't use Math.round like this, it gives the first and last element
            > only half the chance of the others.
            >
            > Use:
            >
            > sT[Math.floor(Math .random() * sT.length)]
            >
            >[/color]
            or:
            sT[new Date()%sT.lengt h]

            Mick

            Comment

            • RobG

              #7
              Re: Whats wrong with this?

              Lee wrote:[color=blue]
              > RobG said:
              >[/color]
              [...][color=blue][color=green]
              >>
              >> <script type="text/javascript" src="here.js"></script>
              >> <script type="text/javascript">
              >> document.write( sT[Math.round((sT. length-1)*Math.random( ))]);[/color]
              >
              >
              > Using Math.round() underselects the first and last elements of the array.
              > sT[Math.floor(Math .random()*sT.le ngth)]
              >[/color]

              I was going to comment on the possibility that the selection was not
              even for all elements in the array, however using Math.floor as
              suggested infers that Math.random will *never* return 1, or at least
              that the index will never be evaluated to be the length of the array.

              Should that occur, the tip of the day will be 'undefined'.

              The specification says that Math.random will return a value "greater
              than or equal to 0 but less than 1" which means that in theory the
              .floor method is OK, but is it in practice?


              --
              Rob

              Comment

              • Richard Cornford

                #8
                Re: Whats wrong with this?

                RobG wrote:[color=blue]
                > Lee wrote:[/color]
                <snip>[color=blue][color=green]
                >> Using Math.round() underselects the first and last elements of the
                >> array. sT[Math.floor(Math .random()*sT.le ngth)][/color]
                >
                > I was going to comment on the possibility that the selection was not
                > even for all elements in the array, however using Math.floor as
                > suggested infers that Math.random will *never* return 1, or at least
                > that the index will never be evaluated to be the length of the
                > array.
                >
                > Should that occur, the tip of the day will be 'undefined'.
                >
                > The specification says that Math.random will return a value "greater
                > than or equal to 0 but less than 1" which means that in theory the
                > .floor method is OK, but is it in practice?[/color]

                Apparently a now every old Opera version (I think it was 4 but it may
                have been 5) had a buggy Math.random that did occasionally return 1. I
                have not heard mention of any other javascript versions with the same
                problem. Absolute safety can be guaranteed with - Math.random() % 1 -.

                A faster alternative to Math.floor in this context could be an OR zero
                operation:-

                array.sT[((Math.random() *sT.length) | 0)]

                As OR zero truncates numbers with fractional parts into integers. It
                also restricts the possible range of those integers to 32 bit signed
                integers, which is half of the specified possible range for Array
                indexes (though that should not be a problem in most cases).

                Richard.


                Comment

                • Dr John Stockton

                  #9
                  Re: Whats wrong with this?

                  JRS: In article <nGC3e.1737$6a5 .595@twister.ny roc.rr.com>, dated Sat, 2
                  Apr 2005 19:48:35, seen in news:comp.lang. javascript, Mick White
                  <mwhite13BOGUS@ rochester.rr.co m> posted :[color=blue]
                  >Lasse Reichstein Nielsen wrote:[color=green]
                  >> RobG <rgqld@iinet.ne t.auau> writes:
                  >>
                  >>[color=darkred]
                  >>> document.write( sT[Math.round((sT. length-1)*Math.random( ))]);[/color]
                  >>
                  >> ...
                  >>[color=darkred]
                  >>> is all that is required.[/color]
                  >>
                  >>
                  >> Don't use Math.round like this, it gives the first and last element
                  >> only half the chance of the others.
                  >>
                  >> Use:
                  >>
                  >> sT[Math.floor(Math .random() * sT.length)]
                  >>
                  >>[/color]
                  > or:
                  >sT[new Date()%sT.lengt h][/color]

                  I think that the OP has a 5-element array.
                  Have you tried your method with 5 or 10 elements in the array?
                  Actually, AFAIK, it *might* work in XP, and *might* in non-PC; but I
                  don't expect it to in NT, and it does not in Win98.

                  Do any systems show a 1 ms resolution for X = new Date() ?

                  <FAQENTRY> :

                  I find that
                  (Math.random()* 10)|0
                  is appreciably faster than
                  Math.floor(Math .random()*10)
                  although the latter might be considered more readable.

                  If tests on other systems show similar results, ISTM that it would be
                  worth adding the former to FAQ 4.22, and taking the opportunity to
                  remark that |0 can beat Math.floor.

                  --
                  © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                  <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of 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

                  • Mick White

                    #10
                    Re: Whats wrong with this?

                    Dr John Stockton wrote:
                    [color=blue]
                    > JRS: In article <nGC3e.1737$6a5 .595@twister.ny roc.rr.com>, dated Sat, 2
                    > Apr 2005 19:48:35, seen in news:comp.lang. javascript, Mick White
                    > <mwhite13BOGUS@ rochester.rr.co m> posted :
                    >[color=green]
                    >>Lasse Reichstein Nielsen wrote:
                    >>[color=darkred]
                    >>>RobG <rgqld@iinet.ne t.auau> writes:
                    >>>
                    >>>
                    >>>
                    >>>> document.write( sT[Math.round((sT. length-1)*Math.random( ))]);
                    >>>
                    >>>...
                    >>>
                    >>>
                    >>>> is all that is required.
                    >>>
                    >>>
                    >>>Don't use Math.round like this, it gives the first and last element
                    >>>only half the chance of the others.
                    >>>
                    >>>Use:
                    >>>
                    >>> sT[Math.floor(Math .random() * sT.length)]
                    >>>
                    >>>[/color]
                    >>
                    >> or:
                    >>sT[new Date()%sT.lengt h][/color]
                    >
                    >
                    > I think that the OP has a 5-element array.
                    > Have you tried your method with 5 or 10 elements in the array?
                    > Actually, AFAIK, it *might* work in XP, and *might* in non-PC; but I
                    > don't expect it to in NT, and it does not in Win98.
                    >[/color]
                    Well, John, new Date() is cast as a Number in a Modulus operation.

                    sT[new Date().getTime( )%sT.length] will force the conversion though, and
                    create equal distribution of the array entries. Since the datestamp is a
                    large dynamic number, its use is ideal in this scenario (one off).
                    I don't know why it wouldn't work in NT or Win98, please educate me.
                    Mick



                    Do any systems show a 1 ms resolution for X = new Date() ?[color=blue]
                    >
                    > <FAQENTRY> :
                    >
                    > I find that
                    > (Math.random()* 10)|0
                    > is appreciably faster than
                    > Math.floor(Math .random()*10)
                    > although the latter might be considered more readable.
                    >
                    > If tests on other systems show similar results, ISTM that it would be
                    > worth adding the former to FAQ 4.22, and taking the opportunity to
                    > remark that |0 can beat Math.floor.
                    >[/color]

                    Comment

                    • Lasse Reichstein Nielsen

                      #11
                      Re: Whats wrong with this?

                      Mick White <mwhite13BOGUS@ rochester.rr.co m> writes:

                      [color=blue]
                      > Well, John, new Date() is cast as a Number in a Modulus operation.[/color]

                      Correct.
                      [color=blue]
                      > sT[new Date().getTime( )%sT.length] will force the conversion though,
                      > and create equal distribution of the array entries.[/color]

                      Force conversion, yes. Guarantee equal distribution ... no.
                      [color=blue]
                      > Since the datestamp is a large dynamic number, its use is ideal in
                      > this scenario (one off). I don't know why it wouldn't work in NT or
                      > Win98, please educate me.[/color]

                      Because the granularity of the millisecond counter isn't necessarily
                      as small as you hope. What if the counter incremented exactly once
                      every 10ms? Then doing new Date()%5 would not be very random.

                      In a simple test (both IE 6 and Opera 8 on WinXP/SP2) I found the
                      result of new Date()%10 to be scewed, with 4 and 9 having only half
                      the frequency of the other results.

                      In fact, the values of new Date().getTime( ) seems to increment in steps
                      of 15 or 16 (the increases appears to repeat the sequence
                      15 16 15 16 16 15 16 16
                      i.e., eight increases in 125 ms).

                      So, the answer is that Date is simply not random enough.
                      /L
                      --
                      Lasse Reichstein Nielsen - lrn@hotpop.com
                      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                      'Faith without judgement merely degrades the spirit divine.'

                      Comment

                      • Mick White

                        #12
                        Re: Whats wrong with this?

                        Lasse Reichstein Nielsen wrote:
                        [color=blue]
                        > Mick White <mwhite13BOGUS@ rochester.rr.co m> writes:[/color]
                        [..][color=blue]
                        >[color=green]
                        >>Since the datestamp is a large dynamic number, its use is ideal in
                        >>this scenario (one off). I don't know why it wouldn't work in NT or
                        >>Win98, please educate me.[/color]
                        >
                        >
                        > Because the granularity of the millisecond counter isn't necessarily
                        > as small as you hope. What if the counter incremented exactly once
                        > every 10ms? Then doing new Date()%5 would not be very random.
                        >
                        > In a simple test (both IE 6 and Opera 8 on WinXP/SP2) I found the
                        > result of new Date()%10 to be scewed, with 4 and 9 having only half
                        > the frequency of the other results.
                        >
                        > In fact, the values of new Date().getTime( ) seems to increment in steps
                        > of 15 or 16 (the increases appears to repeat the sequence
                        > 15 16 15 16 16 15 16 16
                        > i.e., eight increases in 125 ms).
                        >
                        > So, the answer is that Date is simply not random enough.
                        > /L[/color]

                        Thanks for the response, Lasse, my own test doesn't appear to support
                        your assertion.

                        http://home.rochester.rr.com/mickweb...pt/random.html

                        Where I display new Date()%10 at 250 random intervals of one second or less.

                        Methodology flawed?
                        Mick




                        Comment

                        • RobG

                          #13
                          Re: Whats wrong with this?

                          Mick White wrote:[color=blue]
                          > Lasse Reichstein Nielsen wrote:
                          >[color=green]
                          >> Mick White <mwhite13BOGUS@ rochester.rr.co m> writes:[/color]
                          >
                          > [..]
                          >[color=green]
                          >>[color=darkred]
                          >>> Since the datestamp is a large dynamic number, its use is ideal in
                          >>> this scenario (one off). I don't know why it wouldn't work in NT or
                          >>> Win98, please educate me.[/color]
                          >>
                          >>
                          >>
                          >> Because the granularity of the millisecond counter isn't necessarily
                          >> as small as you hope. What if the counter incremented exactly once
                          >> every 10ms? Then doing new Date()%5 would not be very random.
                          >>
                          >> In a simple test (both IE 6 and Opera 8 on WinXP/SP2) I found the
                          >> result of new Date()%10 to be scewed, with 4 and 9 having only half
                          >> the frequency of the other results.
                          >>
                          >> In fact, the values of new Date().getTime( ) seems to increment in steps
                          >> of 15 or 16 (the increases appears to repeat the sequence 15 16 15 16
                          >> 16 15 16 16
                          >> i.e., eight increases in 125 ms).
                          >>
                          >> So, the answer is that Date is simply not random enough.
                          >> /L[/color]
                          >
                          >
                          > Thanks for the response, Lasse, my own test doesn't appear to support
                          > your assertion.
                          >
                          > http://home.rochester.rr.com/mickweb...pt/random.html
                          >
                          > Where I display new Date()%10 at 250 random intervals of one second or
                          > less.
                          >
                          > Methodology flawed?[/color]

                          The flaw is expecting an even distribution of values from date() but
                          there is nothing in the ECMA specification that says that must occur.
                          The value of a newly constructed Date object is specified as "the
                          current time" which should be a number indicating a particular
                          instant in time to within a millisecond. There is no accuracy [1]
                          or distribution criterion.

                          On the other hand, the specification states that random() should have
                          an approximately uniform distribution. While that does not guarantee
                          an even distribution, it is more likely to provide one across all
                          systems than date() (or so testing would appear to show, at least in
                          my case).

                          Running the date-based random number selector on my PC gave a
                          significant and consistent over-representation to some values - 2, 4,
                          7 & 9 were about half as likely to occur as the other values.
                          Removing the randomisation of the interval did not change the results
                          (but they happen much faster!)

                          Replacing: d = new Date()%10

                          with JRS's: d = (Math.random()* 10)|0;

                          produced a more even distribution over a number of tests, though
                          typically one value was the mode far more frequently than any other.

                          Code posted below.

                          1. To my understanding, accuracy relates to how close a measurement is
                          to the true value; precision relates to the repeatability of a
                          measurement. So it is possible to have precise measurements that
                          are not accurate.


                          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                          "http://www.w3.org/TR/html4/loose.dtd">
                          <html><head><ti tle>Random?</title>
                          <meta http-equiv="Content-Type"
                          content="text/html; charset=iso-8859-1">
                          <style type="text/css">
                          body {background-color: #FFFFFF;}
                          td {/* font-family: "Courier New", Courier, mono; */
                          font-size: 80%; border: 1px solid green;}
                          table {border-collapse: collapse; padding: 0;}
                          </style></head>
                          <body>
                          <script type="text/JavaScript">
                          function R(f){
                          var t = f.timerand[0].checked;
                          document.getEle mentById('tType ').innerHTML = (t)?'time':'ran dom';
                          var mod = f.modulus.value ;
                          var tb = document.getEle mentById('tbA') ;
                          var oR, oT, i = 0, times = 0;
                          do {
                          if (!document.getE lementById('f'+ i)) {
                          oR = document.create Element('TR');
                          oT = document.create Element('TD');
                          oT.appendChild( document.create TextNode(i));
                          pT = document.create Element('TD');
                          pT.id = "f"+i;
                          oR.appendChild( oT);
                          oR.appendChild( pT);
                          tb.appendChild( oR);
                          }
                          } while (++i < mod)

                          while (times++ < 1000) {
                          d = (t)? new Date()% mod : (Math.random()* mod)|0;
                          document.getEle mentById("f"+d) .innerHTML += '' + '.';
                          document.getEle mentById("test" ).innerHTML = ++times;
                          }
                          var count = document.getEle mentById("count ").innerHTM L;
                          document.getEle mentById("count ").innerHTM L = +count + times-1;
                          }
                          </script>
                          <form action="">
                          <input type="radio" name="timerand" value="time" checked>
                          Use time<br>
                          <input type="radio" name="timerand" value="random">
                          Use random<br>
                          <input type="text" name="modulus" value="10" size="5">modulu s<br>
                          <input type="button" value="Run test" onclick="
                          R(this.form);
                          "><br>
                          <input type="reset">
                          </form>
                          <p><span id="test"></span> of <span id="count"></span>
                          using <span id="tType"></span></p>
                          <table>
                          <tbody id="tbA">
                          </tbody>
                          </table>
                          </body>
                          </html>




                          --
                          Rob

                          Comment

                          • Mick White

                            #14
                            Re: Whats wrong with this?

                            RobG wrote:
                            [color=blue]
                            > Mick White wrote:
                            >[color=green]
                            >> Lasse Reichstein Nielsen wrote:
                            >>[color=darkred]
                            >>> Mick White <mwhite13BOGUS@ rochester.rr.co m> writes:[/color]
                            >>
                            >>
                            >> [..]
                            >>[color=darkred]
                            >>>
                            >>>> Since the datestamp is a large dynamic number, its use is ideal in
                            >>>> this scenario (one off). I don't know why it wouldn't work in NT or
                            >>>> Win98, please educate me.
                            >>>
                            >>>
                            >>>
                            >>>
                            >>> Because the granularity of the millisecond counter isn't necessarily
                            >>> as small as you hope. What if the counter incremented exactly once
                            >>> every 10ms? Then doing new Date()%5 would not be very random.
                            >>>
                            >>> In a simple test (both IE 6 and Opera 8 on WinXP/SP2) I found the
                            >>> result of new Date()%10 to be scewed, with 4 and 9 having only half
                            >>> the frequency of the other results.
                            >>>
                            >>> In fact, the values of new Date().getTime( ) seems to increment in steps
                            >>> of 15 or 16 (the increases appears to repeat the sequence 15 16 15
                            >>> 16 16 15 16 16
                            >>> i.e., eight increases in 125 ms).
                            >>>
                            >>> So, the answer is that Date is simply not random enough.
                            >>> /L[/color]
                            >>
                            >>
                            >>
                            >> Thanks for the response, Lasse, my own test doesn't appear to support
                            >> your assertion.
                            >>
                            >> http://home.rochester.rr.com/mickweb...pt/random.html
                            >>
                            >> Where I display new Date()%10 at 250 random intervals of one second or
                            >> less.
                            >>
                            >> Methodology flawed?[/color]
                            >
                            >
                            > The flaw is expecting an even distribution of values from date() but
                            > there is nothing in the ECMA specification that says that must occur.
                            > The value of a newly constructed Date object is specified as "the
                            > current time" which should be a number indicating a particular
                            > instant in time to within a millisecond. There is no accuracy [1]
                            > or distribution criterion.
                            >
                            > On the other hand, the specification states that random() should have
                            > an approximately uniform distribution. While that does not guarantee
                            > an even distribution, it is more likely to provide one across all
                            > systems than date() (or so testing would appear to show, at least in
                            > my case).
                            >
                            > Running the date-based random number selector on my PC gave a
                            > significant and consistent over-representation to some values - 2, 4,
                            > 7 & 9 were about half as likely to occur as the other values.
                            > Removing the randomisation of the interval did not change the results
                            > (but they happen much faster!)
                            >
                            > Replacing: d = new Date()%10
                            >
                            > with JRS's: d = (Math.random()* 10)|0;
                            >
                            > produced a more even distribution over a number of tests, though
                            > typically one value was the mode far more frequently than any other.
                            >
                            > Code posted below.
                            >
                            > 1. To my understanding, accuracy relates to how close a measurement is
                            > to the true value; precision relates to the repeatability of a
                            > measurement. So it is possible to have precise measurements that
                            > are not accurate.
                            >
                            >
                            > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                            > "http://www.w3.org/TR/html4/loose.dtd">
                            > <html><head><ti tle>Random?</title>
                            > <meta http-equiv="Content-Type"
                            > content="text/html; charset=iso-8859-1">
                            > <style type="text/css">
                            > body {background-color: #FFFFFF;}
                            > td {/* font-family: "Courier New", Courier, mono; */
                            > font-size: 80%; border: 1px solid green;}
                            > table {border-collapse: collapse; padding: 0;}
                            > </style></head>
                            > <body>
                            > <script type="text/JavaScript">
                            > function R(f){
                            > var t = f.timerand[0].checked;
                            > document.getEle mentById('tType ').innerHTML = (t)?'time':'ran dom';
                            > var mod = f.modulus.value ;
                            > var tb = document.getEle mentById('tbA') ;
                            > var oR, oT, i = 0, times = 0;
                            > do {
                            > if (!document.getE lementById('f'+ i)) {
                            > oR = document.create Element('TR');
                            > oT = document.create Element('TD');
                            > oT.appendChild( document.create TextNode(i));
                            > pT = document.create Element('TD');
                            > pT.id = "f"+i;
                            > oR.appendChild( oT);
                            > oR.appendChild( pT);
                            > tb.appendChild( oR);
                            > }
                            > } while (++i < mod)
                            >
                            > while (times++ < 1000) {
                            > d = (t)? new Date()% mod : (Math.random()* mod)|0;
                            > document.getEle mentById("f"+d) .innerHTML += '' + '.';
                            > document.getEle mentById("test" ).innerHTML = ++times;
                            > }
                            > var count = document.getEle mentById("count ").innerHTM L;
                            > document.getEle mentById("count ").innerHTM L = +count + times-1;
                            > }
                            > </script>
                            > <form action="">
                            > <input type="radio" name="timerand" value="time" checked>
                            > Use time<br>
                            > <input type="radio" name="timerand" value="random">
                            > Use random<br>
                            > <input type="text" name="modulus" value="10" size="5">modulu s<br>
                            > <input type="button" value="Run test" onclick="
                            > R(this.form);
                            > "><br>
                            > <input type="reset">
                            > </form>
                            > <p><span id="test"></span> of <span id="count"></span>
                            > using <span id="tType"></span></p>
                            > <table>
                            > <tbody id="tbA">
                            > </tbody>
                            > </table>
                            > </body>
                            > </html>
                            >[/color]

                            Nice work, Rob, and I see the efficacy of the built-in random number
                            generator vis a vis that of the Date object. The differences appear to
                            be slight, and the outputs could use some statistical analysis.
                            But I'm convinced (well, almost).

                            Mick

                            Comment

                            • John G Harris

                              #15
                              Re: Whats wrong with this?

                              In article <RUW45DC9B9TCFw Zw@merlyn.demon .co.uk>, Dr John Stockton
                              <spam@merlyn.de mon.co.uk> writes[color=blue]
                              >JRS: In article <nGC3e.1737$6a5 .595@twister.ny roc.rr.com>, dated Sat, 2
                              >Apr 2005 19:48:35, seen in news:comp.lang. javascript, Mick White
                              ><mwhite13BOGUS @rochester.rr.c om> posted :[/color]

                              <snip>[color=blue][color=green]
                              >> or:
                              >>sT[new Date()%sT.lengt h][/color][/color]

                              My system's Date objects supply about 19 different values per second, so
                              the millisecond values are unlikely to be random enough to be useful.


                              <snip>[color=blue]
                              >Do any systems show a 1 ms resolution for X = new Date() ?[/color]
                              <snip>

                              I expect there are, but they needn't be PCs.

                              John
                              --
                              John Harris

                              Comment

                              Working...