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


Groups > comp.lang.javascript > #34161

Re: Random numbers

From emf <emfril@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: Random numbers
Date 2017-10-22 14:55 -0400
Organization Aioe.org NNTP Server
Message-ID <osipj9$lfm$1@gioia.aioe.org> (permalink)
References <osa2ld$6t0$1@gioia.aioe.org> <ose4is$14l2$1@gioia.aioe.org> <19e8d664-5c4b-4118-99de-5133a2317841@googlegroups.com>

Show all headers | View raw


On 2017-10-21 12:47, Michael Haufe (TNO) wrote:
> emf wrote:
> 
>> The discussion was quite interesting and it gave me leads to pursue. But
>> here is a more specific question: would the following function provide
>> *more* random results than the Math.random()?
>>
>> // returns a random number from 1 to top
>> function random(top) {
>>       var now = new Date();
>>       var hh = now.getHouera();
>>       var mm = now.getMinutes();
>>       var ss = now.getSeconds();
>>       var ms = now.getMilliseconds();
>>       var tim = (hh * 1440000) + (mm * 60000) + (ss * 1000) +  ms;
>>       var rndm = (tim % top) + 1;
>>       return rndm;
>> }
> 
> Given that Math.random is implementation dependent [1] it's possible for one to create a better one, but yours is broken.
> 
> random(1) => 1
> random(0) => NaN

Easily fixed. My problem was that using one of my eye execrcises

https://emf.neocities.org/ix/ix3.html

when clicking the button while pressing Ctrl (for now a hidden feature) 
I would get into a "random" stanza of a 156 stanza poem. After, however, 
a few months, I realized that I was often getting into the same points, 
and never into some others. I suspect that my function will provide more 
"random" results, since the exact millisecond of a minute (OK, of an 
hour seems overkill) seems to me quite random.

Eustace

-- 
Spherical Triangle Calculator
http://emf.neocities.org/tr/spherical.html

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web