Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #34130 > unrolled thread

Random numbers

Started byemf <emfril@gmail.com>
First post2017-10-19 07:35 -0400
Last post2017-10-28 18:54 +0200
Articles 20 on this page of 35 — 13 participants

Back to article view | Back to comp.lang.javascript


Contents

  Random numbers emf <emfril@gmail.com> - 2017-10-19 07:35 -0400
    Re: Random numbers Julio Di Egidio <julio@diegidio.name> - 2017-10-19 05:03 -0700
    Re: Random numbers Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-10-19 21:06 +0200
      Re: Random numbers "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-10-19 12:10 -0700
        Re: Random numbers Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-10-19 22:04 +0200
          Re: Random numbers "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-10-19 13:41 -0700
            Measuring time (was: Random numbers) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-10-19 22:58 +0200
              Re: Measuring time (was: Random numbers) Dr J R Stockton <J.R.Stockton@physics.org> - 2017-10-24 13:05 -0700
                Re: Measuring time Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-10-25 00:59 +0200
                  Re: Measuring time Dr J R Stockton <J.R.Stockton@physics.org> - 2017-10-25 13:36 -0700
                    Re: Measuring time Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-10-26 19:21 +0200
                Re: Measuring time (was: Random numbers) Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2017-10-26 10:45 +0200
                  Re: Measuring time (was: Random numbers) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-10-26 12:27 +0200
                  Re: Measuring time (was: Random numbers) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-10-26 19:04 +0200
                    Re: Measuring time (was: Random numbers) Hans-Georg Michna <hans-georg@michna.com> - 2017-10-28 11:05 +0200
                    Re: Measuring time (was: Random numbers) Dr J R Stockton <J.R.Stockton@physics.org> - 2017-10-29 03:03 -0700
                      Re: Measuring time (was: Random numbers) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-10-29 17:56 +0100
                        Re: Measuring time (was: Random numbers) dr.j.r.stockton@gmail.com - 2017-10-29 15:12 -0700
                          Re: Measuring time Sam E <why.should.this@be.email.invalid> - 2017-10-29 17:35 -0500
                          Re: Measuring time (was: Random numbers) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-10-30 13:00 +0100
                  Re: Measuring time (was: Random numbers) Tim Slattery <tim@risingdove.com> - 2017-10-26 14:13 -0400
    Re: Random numbers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-10-19 22:21 +0100
      Re: Random numbers Julio Di Egidio <julio@diegidio.name> - 2017-10-19 22:25 -0700
        Re: Random numbers "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2017-10-20 21:52 -0700
          Re: Random numbers Julio Di Egidio <julio@diegidio.name> - 2017-10-20 22:40 -0700
            Re: Random numbers "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2017-10-21 12:40 -0700
              Re: Random numbers Julio Di Egidio <julio@diegidio.name> - 2017-10-21 12:57 -0700
                Re: Random numbers Julio Di Egidio <julio@diegidio.name> - 2017-10-21 12:59 -0700
                  Re: Random numbers "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2017-10-22 16:37 -0700
                    Re: Random numbers Julio Di Egidio <julio@diegidio.name> - 2017-10-22 17:23 -0700
    Re: Random numbers emf <emfril@gmail.com> - 2017-10-20 20:32 -0400
      Re: Random numbers "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-10-21 09:47 -0700
        Re: Random numbers emf <emfril@gmail.com> - 2017-10-22 14:55 -0400
          Re: Random numbers emf <emfril@gmail.com> - 2017-10-27 22:23 -0400
            Re: Random numbers Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-10-28 18:54 +0200

Page 1 of 2  [1] 2  Next page →


#34130 — Random numbers

Fromemf <emfril@gmail.com>
Date2017-10-19 07:35 -0400
SubjectRandom numbers
Message-ID<osa2ld$6t0$1@gioia.aioe.org>
I am wondering if there is a better (but still not too complicated) way 
to generate random numbers then the Math.random(). My idea is to get the 
microseconds, multiply them by, say 10000, bet the integer, and then the 
modulus of that. Wouldn't that give more random numbers?

Thanks,

Eustace

-- 
Natal Transits Calculator
http://emf.neocities.org/nt/nataltransits2.html

[toc] | [next] | [standalone]


#34131

FromJulio Di Egidio <julio@diegidio.name>
Date2017-10-19 05:03 -0700
Message-ID<40c40c41-a694-4d56-986e-4c4e684de505@googlegroups.com>
In reply to#34130
On Thursday, October 19, 2017 at 1:35:21 PM UTC+2, emf wrote:

> I am wondering if there is a better (but still not too complicated)
> way to generate random numbers then the Math.random().

Simplest and works across all recent browsers:

<https://developer.mozilla.org/en-US/docs/Web/API/RandomSource/getRandomValues>

Here is the fine print:

<< The PRNG used differs from one implementation to the other but is
suitable for cryptographic usages. Implementations are [...] required
to use a seed with enough entropy, like a system-level entropy source. >>

Julio

[toc] | [prev] | [next] | [standalone]


#34136

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-10-19 21:06 +0200
Message-ID<2345791.k3LOHGUjKi@PointedEars.de>
In reply to#34130
emf wrote:
^^^
It is considered polite here to posting using one’s real name.

> I am wondering if there is a better (but still not too complicated) way
> to generate random numbers then the Math.random(). My idea is to get the
> microseconds,
  ^^^^^^^^^^^^
That is not possible.

> multiply them by, say 10000, bet the integer, and then the modulus of
> that. Wouldn't that give more random numbers?

That depends on what you mean by “bet the integer”.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#34138

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2017-10-19 12:10 -0700
Message-ID<edfd27c0-30b9-40e6-b265-f7da17d99a0d@googlegroups.com>
In reply to#34136
On Thursday, October 19, 2017 at 2:06:16 PM UTC-5, Thomas 'PointedEars' Lahn wrote:
> emf wrote:
> ^^^
> It is considered polite here to posting using one’s real name.
> 
> > I am wondering if there is a better (but still not too complicated) way
> > to generate random numbers then the Math.random(). My idea is to get the
> > microseconds,
>   ^^^^^^^^^^^^
> That is not possible.


There is a new API:

https://developer.mozilla.org/en-US/docs/Web/API/Performance/now

[toc] | [prev] | [next] | [standalone]


#34143

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-10-19 22:04 +0200
Message-ID<2876676.AJdgDx1Vlc@PointedEars.de>
In reply to#34138
Michael Haufe (TNO) wrote:

> On Thursday, October 19, 2017 at 2:06:16 PM UTC-5, Thomas 'PointedEars'
> Lahn wrote:

Attribution _line_, not attribution novel.

>> emf wrote:
>> > I am wondering if there is a better (but still not too complicated) way
>> > to generate random numbers then the Math.random(). My idea is to get
>> > the microseconds,
>>   ^^^^^^^^^^^^
>> That is not possible.
> 
> There is a new API:
> 
> https://developer.mozilla.org/en-US/docs/Web/API/Performance/now

Thanks, but if you read more carefully: Although it *can* be accurate to *5* 
microseconds *if the device supports it* ? it is only *guaranteed* to be 
accurate to milliseconds ?, it does _not_ provide the *time from epoch* (or 
anything like that) in microseconds then, and therefore makes for a *worse* 
PRNG seed value than new Date().getTime().

Because it is intended to measure *performance*, _not_ to produce pseudo-
random numbers.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#34144

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2017-10-19 13:41 -0700
Message-ID<8f442f26-987b-4482-bf5f-775856a0a3b8@googlegroups.com>
In reply to#34143
Thomas 'PointedEars' Lahn wrote:
> Michael Haufe (TNO) wrote:
> 
> > On Thursday, October 19, 2017 at 2:06:16 PM UTC-5, Thomas 'PointedEars'
> > Lahn wrote:
> 
> Attribution _line_, not attribution novel.

ACK

> >> emf wrote:
> >> > I am wondering if there is a better (but still not too complicated) way
> >> > to generate random numbers then the Math.random(). My idea is to get
> >> > the microseconds,
> >>   ^^^^^^^^^^^^
> >> That is not possible.
> > 
> > There is a new API:
> > 
> > https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
> 
> Thanks, but if you read more carefully: Although it *can* be accurate to *5* 
> microseconds *if the device supports it* ? it is only *guaranteed* to be 
> accurate to milliseconds ?, it does _not_ provide the *time from epoch* (or 
> anything like that) in microseconds then, and therefore makes for a *worse* 
> PRNG seed value than new Date().getTime().

More of an FYI of its existence to move the needle away from "That is not possible"

> Because it is intended to measure *performance*, _not_ to produce pseudo-
> random numbers.

Indeed

[toc] | [prev] | [next] | [standalone]


#34145 — Measuring time (was: Random numbers)

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-10-19 22:58 +0200
SubjectMeasuring time (was: Random numbers)
Message-ID<5883795.4vTCxPXJkl@PointedEars.de>
In reply to#34144
Michael Haufe (TNO) wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Thanks, but if you read more carefully: Although it *can* be accurate to
>> *5* microseconds *if the device supports it* ? it is only *guaranteed* to
>> be accurate to milliseconds ?, it does _not_ provide the *time from
>> epoch* (or anything like that) in microseconds then, and therefore makes
>> for a *worse* PRNG seed value than new Date().getTime().
> 
> More of an FYI of its existence to move the needle away from "That is not
> possible"

ACK.

Apropos, it had just occurred to me (when reading that the first time the 
on-board cesium clocks of the GPS NTS-2 satellite were tested was on “day 
190, 1977”) that you can obtain the date for day N of year Y using

  new Date(Y, 0, N)

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#34184 — Re: Measuring time (was: Random numbers)

FromDr J R Stockton <J.R.Stockton@physics.org>
Date2017-10-24 13:05 -0700
SubjectRe: Measuring time (was: Random numbers)
Message-ID<7b7114cd-8e1a-49f3-b69f-9a23e95d280c@googlegroups.com>
In reply to#34145
On Thursday, October 19, 2017 at 9:58:26 PM UTC+1, Thomas 'PointedEars' Lahn wrote:

 > Apropos, it had just occurred to me (when reading that the first time the 
> on-board cesium clocks of the GPS NTS-2 satellite were tested was on “day 
> 190, 1977”) that you can obtain the date for day N of year Y using
> 
>   new Date(Y, 0, N)

The likelihood of that is fairly obvious on considering

ECMA-262-1, Jun 1997, 15.9.1.12 MakeDay(year, month, date), list entry 1
or
ECMA-262-7, Jun 2016, 20.3.1.13 MakeDay (year, month, date), list entry 1
or I suppose the corresponding parts of all other ECMA-262.

IIRC, new Date(Y, 0, N) fails for years 0 to 99; and MD is wrong for most of Year 0.

-- 
  (c) John Stockton, near London, UK.  Using Google, no spell-check. |
 Mail: J.R.""""""""@physics.org                                      |

[toc] | [prev] | [next] | [standalone]


#34190 — Re: Measuring time

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-10-25 00:59 +0200
SubjectRe: Measuring time
Message-ID<4491754.69AeqWupk3@PointedEars.de>
In reply to#34184
Dr J R Stockton wrote:

> On Thursday, October 19, 2017 at 9:58:26 PM UTC+1, Thomas 'PointedEars'
> Lahn wrote:

Attribution line, not attribution novel.

>  > Apropos, it had just occurred to me (when reading that the first time
>  > the
>> on-board cesium clocks of the GPS NTS-2 satellite were tested was on “day
>> 190, 1977”) that you can obtain the date for day N of year Y using
>> 
>>   new Date(Y, 0, N)
> 
> The likelihood of that is fairly obvious on considering
> 
> ECMA-262-1, Jun 1997, 15.9.1.12 MakeDay(year, month, date), list entry 1
> or
> ECMA-262-7, Jun 2016, 20.3.1.13 MakeDay (year, month, date), list entry 1
> or I suppose the corresponding parts of all other ECMA-262.

(You are preaching to the choir.)  I thought that to be obvious.
 
> IIRC, new Date(Y, 0, N) fails for years 0 to 99;

It fails for those years in V8 JavaScript 5.7.492.63 in Chromium 
57.0.2987.98 on Debian/Devuan GNU+Linux in that they are considered
the years 1900 to 1999 CE instead (also see below):

| -> new Date(99, 0, 1)
| <- Fri Jan 01 1999 00:00:00 GMT+0100 (CET)

However, while “new Date(0, 0, 1)” cannot be used to produce January 1,
1 BCE according to the Proleptic Gregorian calendar, it is apparently 
possible to do that in another way:

| -> var d = new Date(0, 0, 1); console.log(d); d.setFullYear(0);
|    console.log(d);
| Mon Jan 01 1900 00:00:00 GMT+0100 (CET)
| Sat Jan 01    0 00:00:00 GMT+0100 (CET)

<https://en.wikipedia.org/wiki/1_BC> says that it was a Saturday indeed.

> and MD is wrong for most of Year 0.

That is a matter of interpretation or, if understood as specified, it does 
not appear to be the case in that implementation (see above).  According to 
Wikipedia, 1999-01-01 CE *was* a Monday indeed:

<https://en.wikipedia.org/wiki/January_1900#January_1.2C_1900_.28Monday.29>

Please clarify, or cite evidence to support, your assumption.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#34194 — Re: Measuring time

FromDr J R Stockton <J.R.Stockton@physics.org>
Date2017-10-25 13:36 -0700
SubjectRe: Measuring time
Message-ID<f89fc038-a9ed-4df5-9d41-3a0b096f944f@googlegroups.com>
In reply to#34190
On Tuesday, October 24, 2017 at 11:59:40 PM UTC+1, Thomas 'PointedEars' Lahn wrote:
> Dr J R Stockton wrote:
> 
> > On Thursday, October 19, 2017 at 9:58:26 PM UTC+1, Thomas 'PointedEars'
> > Lahn wrote:
> 
> Attribution line, not attribution novel.

OAF.

> >  > Apropos, it had just occurred to me (when reading that the first time
> >  > the
> >> on-board cesium clocks of the GPS NTS-2 satellite were tested was on “day
> >> 190, 1977”) that you can obtain the date for day N of year Y using
> >> 
> >>   new Date(Y, 0, N)
> > 
> > The likelihood of that is fairly obvious on considering
> > 
> > ECMA-262-1, Jun 1997, 15.9.1.12 MakeDay(year, month, date), list entry 1
> > or
> > ECMA-262-7, Jun 2016, 20.3.1.13 MakeDay (year, month, date), list entry 1
> > or I suppose the corresponding parts of all other ECMA-262.
> 
> (You are preaching to the choir.)  I thought that to be obvious.


It is, and it was well known long ago to many of us here,
so why did you write "it had just occurred to me", which
implies surprise?  Perhaps you meant "I had just remembered".

  
> > IIRC, new Date(Y, 0, N) fails for years 0 to 99;

<<< Of course, that is not a true failure, as can be seen
    by searching the Standard for the string "1900".  It is
    just an inanity of the Originators, as is getYear not
    doing what getFullYear was later added to do.

> It fails for those years in V8 JavaScript 5.7.492.63 in Chromium 
> 57.0.2987.98 on Debian/Devuan GNU+Linux in that they are considered
> the years 1900 to 1999 CE instead (also see below):
> 
> | -> new Date(99, 0, 1)
> | <- Fri Jan 01 1999 00:00:00 GMT+0100 (CET)
> 
> However, while “new Date(0, 0, 1)” cannot be used to produce January 1,
> 1 BCE according to the Proleptic Gregorian calendar, it is apparently 
> possible to do that in another way:
> 
> | -> var d = new Date(0, 0, 1); console.log(d); d.setFullYear(0);
> |    console.log(d);
> | Mon Jan 01 1900 00:00:00 GMT+0100 (CET)
> | Sat Jan 01    0 00:00:00 GMT+0100 (CET)

It is easier to use   var d = new Date(100, -1200, 1)  or some
variant thereof, such as   var d = new Date(-100, 1200, 1) ;
one can indeed use var d = new Date(400, 0, 1-400*365.2425) .
And easier still : var d = new Date(-1, 12, 1) .



> <https://en.wikipedia.org/wiki/1_BC> says that it was a Saturday indeed.
> 
> > and MD is wrong for most of Year 0.
> 
> That is a matter of interpretation or, if understood as specified, it does 
> not appear to be the case in that implementation (see above).  According to 
> Wikipedia, 1999-01-01 CE *was* a Monday indeed:

But, according to my relevant IoP diary, 1999-01-01 was a Friday.

The obvious handy authority for the secular proleptic Gregorian year
zero is the civil calendar for years 2000 += n*28, for |n|<4.  That
IoP diary says that the year 2000 was Saturday to Sunday; therefore
2001-001 = 2001-W01-1 (sic) was a Monday, as was fairly well
known at the time.

-- 
  (c) John Stockton, near London, UK.  Using Google, no spell-check. |
 Mail: J.R.""""""""@physics.org                                      |

[toc] | [prev] | [next] | [standalone]


#34215 — Re: Measuring time

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-10-26 19:21 +0200
SubjectRe: Measuring time
Message-ID<2074425.ElGaqSPkdT@PointedEars.de>
In reply to#34194
Dr J R Stockton wrote:

> On Tuesday, October 24, 2017 at 11:59:40 PM UTC+1, Thomas 'PointedEars'
> Lahn wrote:
>> Dr J R Stockton wrote:
>> > On Thursday, October 19, 2017 at 9:58:26 PM UTC+1, Thomas 'PointedEars'
>> > Lahn wrote:
>> 
>> Attribution line, not attribution novel.
> 
> OAF.

No, I do not think that the Open Access Framework has something to do with 
it.
 
>> >  > Apropos, it had just occurred to me (when reading that the first
>> >  > time the
>> >> on-board cesium clocks of the GPS NTS-2 satellite were tested was on
>> >> “day 190, 1977”) that you can obtain the date for day N of year Y
>> >> using
>> >>   new Date(Y, 0, N)
>> > The likelihood of that is fairly obvious on considering
>> > 
>> > ECMA-262-1, Jun 1997, 15.9.1.12 MakeDay(year, month, date), list entry
>> > 1 or
>> > ECMA-262-7, Jun 2016, 20.3.1.13 MakeDay (year, month, date), list entry
>> > 1 or I suppose the corresponding parts of all other ECMA-262.
>> 
>> (You are preaching to the choir.)  I thought that to be obvious.
> 
> It is, and it was well known long ago to many of us here,

It turns out that the MakeDay() algorithm was never the reason, but the Date 
constructor itself:  From

<http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,
%201st%20edition,%20June%201997.pdf>

to

,-<http://www.ecma-international.org/ecma-262/8.0/#sec-date-year-month-date-hours-minutes-seconds-ms>
| 
| […]
| h. If y is not NaN and 0 ≤ ToInteger(y) ≤ 99, then let yr be
|    1900+ToInteger(y); otherwise, let yr be y.

> so why did you write "it had just occurred to me",

That follows from my description.

> which implies surprise? 

More like coincidence in this case.

> Perhaps you meant "I had just remembered".

No.

>> > IIRC, new Date(Y, 0, N) fails for years 0 to 99;
> 
> <<< Of course, that is not a true failure, as can be seen
>     by searching the Standard for the string "1900".  It is
>     just an inanity of the Originators, as is getYear not
>     doing what getFullYear was later added to do.

ACK.
 
>> It fails for those years in V8 JavaScript 5.7.492.63 in Chromium
>> 57.0.2987.98 on Debian/Devuan GNU+Linux in that they are considered
>> the years 1900 to 1999 CE instead (also see below):
>> 
>> | -> new Date(99, 0, 1)
>> | <- Fri Jan 01 1999 00:00:00 GMT+0100 (CET)
>> 
>> However, while “new Date(0, 0, 1)” cannot be used to produce January 1,
>> 1 BCE according to the Proleptic Gregorian calendar, it is apparently
>> possible to do that in another way:
>> 
>> | -> var d = new Date(0, 0, 1); console.log(d); d.setFullYear(0);
>> |    console.log(d);
>> | Mon Jan 01 1900 00:00:00 GMT+0100 (CET)
>> | Sat Jan 01    0 00:00:00 GMT+0100 (CET)
> 
> It is easier to use   var d = new Date(100, -1200, 1)  or some
> variant thereof, such as   var d = new Date(-100, 1200, 1) ;
> one can indeed use var d = new Date(400, 0, 1-400*365.2425) .
> And easier still : var d = new Date(-1, 12, 1) .

Easier maybe, but not as reliable, and certainly harder to maintain.
A wrapper constructor that calls setFullYear() if necessary appears to be 
the better approach.

>> <https://en.wikipedia.org/wiki/1_BC> says that it was a Saturday indeed.
>> 
>> > and MD is wrong for most of Year 0.
>> 
>> That is a matter of interpretation or, if understood as specified, it
>> does not appear to be the case in that implementation (see above). 
>> According to Wikipedia, 1999-01-01 CE *was* a Monday indeed:
                           ^^^^
> But, according to my relevant IoP diary, 1999-01-01 was a Friday.

Yes; this was a typo, as you can see if you consider the source code.
 
> The obvious handy authority for the secular proleptic Gregorian year
> zero is the civil calendar for years 2000 += n*28, for |n|<4.  That
> IoP diary says that the year 2000 was Saturday to Sunday; therefore
> 2001-001 = 2001-W01-1 (sic) was a Monday, as was fairly well
> known at the time.

I do not follow.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#34197 — Re: Measuring time (was: Random numbers)

FromHans-Georg Michna <hans-georgNoEmailPlease@michna.com>
Date2017-10-26 10:45 +0200
SubjectRe: Measuring time (was: Random numbers)
Message-ID<kt73vcpiuul20rm04b0pmf7d1ontqc6q04@4ax.com>
In reply to#34184
On Tue, 24 Oct 2017 13:05:49 -0700 (PDT), Dr J R Stockton wrote:

>IIRC, new Date(Y, 0, N) fails for years 0 to 99; and MD is wrong for most of Year 0.

I don't know about years 1 to 99, but there is no year 0.

As a mathematically thinking person I hate it, but that's how
the year numbers are defined. There is a year "anno domini" 1
and a year 1 "before Christ" or BCE (before the common era), but
no year zero. Ugly, ugly.

Hans-Georg

[toc] | [prev] | [next] | [standalone]


#34203 — Re: Measuring time (was: Random numbers)

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2017-10-26 12:27 +0200
SubjectRe: Measuring time (was: Random numbers)
Message-ID<XnsA81A7EADCDDE1eejj99@194.109.6.166>
In reply to#34197
Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> wrote on 26 Oct 2017 
in comp.lang.javascript:

> As a mathematically thinking person I hate it, but that's how
> the year numbers are defined. There is a year "anno domini" 1
> and a year 1 "before Christ" or BCE (before the common era), but
> no year zero. Ugly, ugly.

Ugly, ugly, as, while bce exists, christ most probably did not,
and even the 'fake' story says he was born in 4 bce,
and that values 'above' 10000 bce did not.

btw, the same goes for storey, as in floor, 
which while it can be negative,
has no zero in the US, while it has in Europe. 

Mezzanines may or may not be counted as storeys,
13th are sometimes skipped by US superstition,
and Trump tower has 10 fake floors.

btw, I love a positive story, even when fixional.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#34214 — Re: Measuring time (was: Random numbers)

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-10-26 19:04 +0200
SubjectRe: Measuring time (was: Random numbers)
Message-ID<4045820.LvFx2qVVIh@PointedEars.de>
In reply to#34197
Hans-Georg Michna wrote:

> On Tue, 24 Oct 2017 13:05:49 -0700 (PDT), Dr J R Stockton wrote:
>> IIRC, new Date(Y, 0, N) fails for years 0 to 99; and MD is wrong for most
>> of Year 0.
> 
> I don't know about years 1 to 99, but there is no year 0. […]

In the Proleptic Gregorian calendar as specified in ISO 8601 and implemented 
by implementations of ECMA-262-3 and later, year 0 is equivalent to 1 BCE:

<https://en.wikipedia.org/wiki/Year_zero>

AFAICS, the result for Y === 0 is only wrong (not as specified) if N < 366 
and one expects a date that is not in 1900 CE.  This behavior of the Date 
constructor has historical reasons, but, as I showed, can be worked around.


Unfortunately, although your address header fields have changed, they are 
still invalid, so I have augmented my killfile with their new values.  Note 
that you are not only disregarding Netiquette, but also violating the Terms 
of Use of your service provider which “may result in immediate account 
revocation”.

<http://albasani.net/info/terms_of_use.html.en>

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#34219 — Re: Measuring time (was: Random numbers)

FromHans-Georg Michna <hans-georg@michna.com>
Date2017-10-28 11:05 +0200
SubjectRe: Measuring time (was: Random numbers)
Message-ID<lth8vcd5e0f122bvg2050fl6hbfcadi78a@4ax.com>
In reply to#34214
On Thu, 26 Oct 2017 19:04:59 +0200, Thomas 'PointedEars' Lahn
wrote:

>Unfortunately, although your address header fields have changed, they are 
>still invalid, so I have augmented my killfile with their new values.  Note 
>that you are not only disregarding Netiquette, but also violating the Terms 
>of Use of your service provider which “may result in immediate account 
>revocation”.

Now valid. The reason I did it was that too many usenet users
customarily sent an additional email when replying.

My defense has worked very well through many years, although it
was kind of illegal.

I suspect that usenet is slowly going down, so perhaps the
problem shrinks along with this. I will check how it goes.

Hans-Georg

[toc] | [prev] | [next] | [standalone]


#34226 — Re: Measuring time (was: Random numbers)

FromDr J R Stockton <J.R.Stockton@physics.org>
Date2017-10-29 03:03 -0700
SubjectRe: Measuring time (was: Random numbers)
Message-ID<c2944012-e18e-41ed-be01-8eafeb76f495@googlegroups.com>
In reply to#34214
On Thursday, October 26, 2017 at 6:05:06 PM UTC+1, Thomas 'PointedEars' Lahn wrote:

> > On Tue, 24 Oct 2017 13:05:49 -0700 (PDT), Dr J R Stockton wrote:
> >> IIRC, new Date(Y, 0, N) fails for years 0 to 99; and MD is wrong for most
> >> of Year 0.

> AFAICS, the result for Y === 0 is only wrong (not as specified) if N < 366 
> and one expects a date that is not in 1900 CE.

             There is only one such date; there was no 1900-02-29.

But the following code yields merely 59 :-
      S = ""
      for (N=1 ; N<400 ; N++) {
        D1 = new Date(0e3, 0, N).getDate()
        D2 = new Date(2e3, 0, N).getDate()
        S += "+" + +(D1==D2) }
      eval(S)

In a normal year, January+February is 59 days; the rest are wrong.

-- 
  (c) John Stockton, near London, UK.  Using Google, no spell-check. |
 Mail: J.R.""""""""@physics.org                                      |

[toc] | [prev] | [next] | [standalone]


#34249 — Re: Measuring time (was: Random numbers)

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-10-29 17:56 +0100
SubjectRe: Measuring time (was: Random numbers)
Message-ID<5089967.DvuYhMxLoT@PointedEars.de>
In reply to#34226
Dr J R Stockton wrote:

> […] Thomas 'PointedEars' Lahn wrote:
>> > On Tue, 24 Oct 2017 13:05:49 -0700 (PDT), Dr J R Stockton wrote:
>> >> IIRC, new Date(Y, 0, N) fails for years 0 to 99; and MD is wrong for
>> >> most of Year 0.
>> 
>> AFAICS, the result for Y === 0 is only wrong (not as specified) if N <
>> 366 and one expects a date that is not in 1900 CE.
> 
>              There is only one such date;

No, I meant if one expected a date in 1 BCE instead of 1900 CE.

>              there was no 1900-02-29.

| -> new Date(0, 0, 1)
| <- Mon Jan 01 1900 00:00:00 GMT+0100 (CET)
| 
| -> new Date(0, 1, 29)
| <- Thu Mar 01 1900 00:00:00 GMT+0100 (CET)
 
> But the following code yields merely 59 :-
>       S = ""
>       for (N=1 ; N<400 ; N++) {
>         D1 = new Date(0e3, 0, N).getDate()
>         D2 = new Date(2e3, 0, N).getDate()

Undeclared variable, unwise identifiers.

>         S += "+" + +(D1==D2) }

An Array instance is a lot more efficient for this:

  var a = [];

  for (…)
  {
    a.push("…");
  }

  var s = a.join("+");

>       eval(S)

Please don’t.

  var count = 0;

  for (var n = 1; n < 400; ++n)
  {
    var d1 = (new Date(0e3, 0, n)).getDate();
    var d2 = (new Date(2e3, 0, n)).getDate();
    count += +(d1 == d2);
  }

  console.log(count);
 
> In a normal year, January+February is 59 days; the rest are wrong.

I do not see your point.
 
-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#34251 — Re: Measuring time (was: Random numbers)

Fromdr.j.r.stockton@gmail.com
Date2017-10-29 15:12 -0700
SubjectRe: Measuring time (was: Random numbers)
Message-ID<17d154a1-bc7d-402c-8656-9c48d69d6816@googlegroups.com>
In reply to#34249
On Sunday, 29 October 2017 16:56:30 UTC, Thomas 'PointedEars' Lahn  wrote:
> Dr J R Stockton wrote:

> >              there was no 1900-02-29.
> 
> | -> new Date(0, 0, 1)
> | <- Mon Jan 01 1900 00:00:00 GMT+0100 (CET)
> | 
> | -> new Date(0, 1, 29)
> | <- Thu Mar 01 1900 00:00:00 GMT+0100 (CET)

I prefer to rely on common knowledge of the Gregorian Reform;
IIRC, the 4/100/400-year rules were printed on the back
cover of school exercise books in my day.

But I suggest that section 9 of
<http://www.thelatinlibrary.com/gravissimas.html> is more
authoritative than relying on software.

  
> > But the following code yields merely 59 :-
> >       S = ""
> >       for (N=1 ; N<400 ; N++) {
> >         D1 = new Date(0e3, 0, N).getDate()
> >         D2 = new Date(2e3, 0, N).getDate()
> 
> Undeclared variable, unwise identifiers.

Irrelevant; single-use code, not saved to disc.

 
> >         S += "+" + +(D1==D2) }
> 
> An Array instance is a lot more efficient for this:

No; it would take longer to type, and I had wanted to see
S in its full glory before completion.  Execution was
effectively instantaneous.

    var a = [];
> 
>   for (…)
>   {
>     a.push("…");
>   }
> 
>   var s = a.join("+");
> 
> >       eval(S)
> 
> Please don’t.
> 
>   var count = 0;
> 
>   for (var n = 1; n < 400; ++n)
>   {
>     var d1 = (new Date(0e3, 0, n)).getDate();
>     var d2 = (new Date(2e3, 0, n)).getDate();
>     count += +(d1 == d2);
>   }
> 
>   console.log(count);
>  
> > In a normal year, January+February is 59 days; the rest are wrong.
> 
> I do not see your point.

Then think more deeply.  Looking at S may help you.
  
> -- 
> PointedEars
> FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
> <https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
> Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#34252 — Re: Measuring time

FromSam E <why.should.this@be.email.invalid>
Date2017-10-29 17:35 -0500
SubjectRe: Measuring time
Message-ID<CIsJB.34891$E23.15247@fx05.iad>
In reply to#34251
On 10/29/2017 05:12 PM, dr.j.r.stockton@gmail.com wrote:

[snip]

> I prefer to rely on common knowledge of the Gregorian Reform;
> IIRC, the 4/100/400-year rules were printed on the back
> cover of school exercise books in my day.

Those 4/100/400 rules mean the number of days in a (mean) year =
365 + (1/4) - (1/100) + (1/400) = 365.2425 = 31,556,952 seconds.

It would be simpler if the year was a whole number of days, but the day 
and the year are both natural cycles and we can't change that.

We could so something about the months and that %&#$! DST.

[snip]

[toc] | [prev] | [next] | [standalone]


#34264 — Re: Measuring time (was: Random numbers)

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-10-30 13:00 +0100
SubjectRe: Measuring time (was: Random numbers)
Message-ID<5322825.lOV4Wx5bFT@PointedEars.de>
In reply to#34251
dr.j.r.stockton@gmail.com wrote:

> On Sunday, 29 October 2017 16:56:30 UTC, Thomas 'PointedEars' Lahn  wrote:
>> Dr J R Stockton wrote:
>> >              there was no 1900-02-29.
>> 
>> | -> new Date(0, 0, 1)
>> | <- Mon Jan 01 1900 00:00:00 GMT+0100 (CET)
>> | 
>> | -> new Date(0, 1, 29)
>> | <- Thu Mar 01 1900 00:00:00 GMT+0100 (CET)
> 
> I prefer to rely on common knowledge of the Gregorian Reform;
> IIRC, the 4/100/400-year rules were printed on the back
> cover of school exercise books in my day.
> 
> But I suggest that section 9 of
> <http://www.thelatinlibrary.com/gravissimas.html> is more
> authoritative than relying on software.

ISTM that you have not read my posting(s) carefully enough.  The 
implementation confirms your claim that there was no 1900-02-29 CE,
which disproves your claim that

>>> There is only one such date; there was no 1900-02-29.

in reply to my

>> AFAICS, the result for [new Date(0, 1, N)] is only wrong (not as
>> specified) if N < 366 and one expects a date that is not in 1900 CE.

which I have explained how it was meant.

>> > But the following code yields merely 59 :-
>> >       S = ""
>> >       for (N=1 ; N<400 ; N++) {
>> >         D1 = new Date(0e3, 0, N).getDate()
>> >         D2 = new Date(2e3, 0, N).getDate()
>> 
>> Undeclared variable, unwise identifiers.
> 
> Irrelevant; single-use code, not saved to disc.

Examples posted here should meeet the minimum standards of recommendable 
ECMAScript code.
  
>> >         S += "+" + +(D1==D2) }
>> 
>> An Array instance is a lot more efficient for this:
> 
> No; it would take longer to type,

It would not.

> and I had wanted to see S in its full glory before completion.

You do not have to see it as a *string* value.  

> Execution was effectively instantaneous.

Addition is available directly as I showed, and indirectly through the 
Array.prototype.reduce() method.  There is no need for inefficient 
concatenation or evil eval() [tm].

  var a = Array.apply(null, {length: 10}).map((e, i) => i);

  /* [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] */
  console.log(a);

  var notGauss = a.reduce((accu, e) => accu + e);

  /* 45 */
  console.log(notGauss);
 
>> > In a normal year, January+February is 59 days; the rest are wrong.
>> I do not see your point.
> 
> Then think more deeply.

Likewise.

> Looking at S may help you.

It would not.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.javascript


csiph-web