On Fri, Apr 18, 2014 at 7:35 PM, Kevin Gillette
<
extempor...@gmail.com> wrote:
> On Friday, April 18, 2014 7:10:31 AM UTC-6, Jan Mercl wrote:
>>
>> If the source code doesn't help then I apologize - it would
>> require at least few hours for me to write a proper documentation
>> about the algorithm used
>
>
> It'd be helpful if some of the implementation properties were documented.
> For example, does the Pos method return value wrap back to zero when the
> cycle resets (such that Pos and Next are effectively bijective)?
.Pos values have .Cycle modulus. .Cycle >= hi-lo+1. I don't know what
you mean by ".Pos and .Next effectively bijective".
> The
> documentation of Seek seems to imply this. Also, how does NewFC32's hq
> parameter affect the maximum cycle range, if at all? Do we get an effective
> range of ~2 (or is it 4?) billion values no matter what?
First please note that the algorithm is not bound to any specific
limits as seen if FCBig.
Now, the particular FC32 PRNG limits are [math.MinInt32,
math.MaxInt32], which is math.MaxUint32+1 numbers. However, the limits
are configurable in NewFC32. Let's have range r = hi-lo+1. Let's have
the smallest primorial[0] p such that p >= r. Let's have another, but
now greatest primorial such that p/q >= r. Cycle() reports p/q
(int64). The factors of p/q are the positional notation bases the
produced PRNs are computed from. Seeking the next/prev PRN may have to
skip "holes" in Cycle. From the previous it follows there are [0, r)
holes in a Cycle, zero for r being itself a primorial, r-1 if r is a
primoral+1.
The HQ parameter tweaks p, q in such a way (q' = q/2, q > 1) the
number of holes is [0, 2r) (or [r, 2r), not sure now]). This makes the
FCPRNG slower but it improves in the statistical properties of the
produced PRNs*. IIRC, the NIST results[0] for the specific range
used[2] are a bit better than what the math/rand PRNG provides in the
same scenario (or provide 3 years ago).
In the first approximation, PRN-r is like: ... (Pos%B_2)*B_1*B_0 +
(Pos%B_1)*B_0+Pos%B_0 where B_n are factors of p/q. If > r we have hit
a hole a must try again: Pos++.
Proving why it works is the laborious part, this was just a few quick
thoughts, hope it helps...
(*) mod 256. FCPRNGs per se are, by their very nature, progressively
less random towards the end of the cycle.
[0]:
http://en.wikipedia.org/wiki/Primorial
[1]:
https://github.com/cznic/mathutil/blob/master/nist-sts-2-1-1-report
[2]:
https://github.com/cznic/mathutil/blob/master/example/example.go#L27
-j