From: Jorge on
On Apr 12, 5:40 pm, Johannes Baagoe <baa...(a)baagoe.com> wrote:
> (...)
> So, my question is: what are the problems with that approach?

None. It's perfectly legal and It's all right, because a function is
no less an object than any other object, AFAIK.

There's something I'd like to ask you. When you say that the period of
e.g. RandomKISS2007 is greater than 2^123, I wonder how can that be,
given that there are no more than 64 bits in a float. I mean, it will
surely return a repeated value long before 2^123, right ? How can the
period be longer than 2^64, in any case ?

TIA,
--
Jorge.
From: Jorge on
On Apr 12, 6:40 pm, Jorge <jo...(a)jorgechamorro.com> wrote:
>
> There's something I'd like to ask you. When you say that the period of
> e.g. RandomKISS2007 is greater than 2^123, I wonder how can that be,
> given that there are no more than 64 bits in a float. I mean, it will
> surely return a repeated value long before 2^123, right ? How can the
> period be longer than 2^64, in any case ?

Oh well, I guess that's it, I guess:

"Although PRNGs will repeat their results after they reach the end of
their period, a repeated result does not imply that the end of the
period has been reached, since its internal state may be larger than
its output; this is particularly obvious with PRNGs with a 1-bit
output."
http://en.wikipedia.org/wiki/PRNG
--
Jorge.
From: Scott Sauyet on
Jorge wrote:
> There's something I'd like to ask you. When you say that the period of
> e.g. RandomKISS2007 is greater than 2^123, I wonder how can that be,
> given that there are no more than 64 bits in a float. I mean, it will
> surely return a repeated value long before 2^123, right ? How can the
> period be longer than 2^64, in any case ?

var a = function(i) {return i % 3;} // 0, 1, 2, 0, 1, 2,... period 3
var b = function(i) {return i % 5;} // 0, 1, 2, 3, 4, 0,... period 5

var c = function(i) {return a(i) + b(i);} // 0, 2, 4, 3,... period 15

This of course is not a good function for a random number generator,
but this is the basic technique. The combination of simple periodic
functions has a period that is the least common multiple of their
periods.

-- Scott
From: Jorge on
On Apr 12, 7:32 pm, Scott Sauyet <scott.sau...(a)gmail.com> wrote:
> Jorge wrote:
> > There's something I'd like to ask you. When you say that the period of
> > e.g. RandomKISS2007 is greater than 2^123, I wonder how can that be,
> > given that there are no more than 64 bits in a float. I mean, it will
> > surely return a repeated value long before 2^123, right ? How can the
> > period be longer than 2^64, in any case ?
>
> var a = function(i) {return i % 3;} // 0, 1, 2, 0, 1, 2,... period 3
> var b = function(i) {return i % 5;} // 0, 1, 2, 3, 4, 0,... period 5
>
> var c = function(i) {return a(i) + b(i);} // 0, 2, 4, 3,... period 15
>
> This of course is not a good function for a random number generator,
> but this is the basic technique.  The combination of simple periodic
> functions has a period that is the least common multiple of their
> periods.

Thanks, Scott. I thought -mistakenly- that the period was the distance
between repeated values.
--
Jorge.
From: Dr J R Stockton on
In comp.lang.javascript message <57b4ed7e-8e2e-4e5f-943e-9ceffaa42d18(a)r2
7g2000yqn.googlegroups.com>, Mon, 12 Apr 2010 09:40:09, Jorge
<jorge(a)jorgechamorro.com> posted:
>On Apr 12, 5:40�pm, Johannes Baagoe <baa...(a)baagoe.com> wrote:
>> (...)
>> So, my question is: what are the problems with that approach?
>
>None. It's perfectly legal and It's all right, because a function is
>no less an object than any other object, AFAIK.
>
>There's something I'd like to ask you. When you say that the period of
>e.g. RandomKISS2007 is greater than 2^123, I wonder how can that be,
>given that there are no more than 64 bits in a float. I mean, it will
>surely return a repeated value long before 2^123, right ? How can the
>period be longer than 2^64, in any case ?

The state is not stored in a float.

If you toss a penny in the traditional manner, the state between throws
is stored in exactly 0 bits, and has 1 value. In a set of throws, there
mist be at least one repeated value within every three throws. But the
cycle length is infinite.


My belief is that ECMA 6th Edition should specify that the possible
values of Math.random() shall be N * 2^-53, for N in [0, 2^53[.

N.B. "should" != "will".

--
(c) John Stockton, near London. *@merlyn.demon.co.uk/?.?.Stockton(a)physics.org
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Correct <= 4-line sig. separator as above, a line precisely "-- " (RFC5536/7)
Do not Mail News to me. Before a reply, quote with ">" or "> " (RFC5536/7)