On Tue, Apr 28, 2015 at 7:58 PM, Alexander Burger <a...@software-lab.de> wrote:
> Hi Christophe,

Hi Alex.

> Is it really so important that the random generators give the same
> results?

Not so much important indeed, not crucial, but very interesting!

> I had never intended that. The reason is that the random generator
> should be as simple (fast) as possible,

Let's sum up what we have now concerning pil32 and ersatz:
(rand T) was already OK.
(rand x y) is now ok since the suppression of the (int) cast and the
use of 32 instead of 33.
(rand) is not OK, but I don't use it for the project which needs
reproducibility.

(seed) is not OK, and I'd like the results to match. I'd like my users
to be able to initialize the generator the same way across
implementations. Now what could support my request is the fact that
seed doesn't need to be so efficient since it should not be called
more than once.
What do you think ?

> and all four implementations represent numbers differently:
>
> 1. pil32 […]
> Each bignum cell can hold 32 bits, where the sign
> bit is in bit 0 (no two's complement!). Therefore, the value is
> multiplied by 2, and the sign bit is added.

So this explains the ( n%2==0 ? n/2 : -(n-1)/2 ) trick. Great.
I wonder if this formula really works in all cases.
I tested a lot of cases, but not proved it.
Maybe I should take a pencil and some paper for better chances to convince you.
Or maybe you have a clear vision on this ?

> 2. pil64 […]
>
> 3. miniPicoLisp has only short numbers (in two's complement, either 30
>    bit on 32-bit machines, or 62 bits on 64-bit machines including the
>    sign).

Mmmh. I was not aware of this 30 bit thing.
This will be quite embarrassing when I'll embed in small chips, but not crucial.

> 4. Ersatz […]

And pilMCU ? Ha ha, I'm just curious !

> So there is no "natural" way to get completely equal results.

Indeed, but for my purpose, I only need:
* pil32 (mainly for my dev machine, but not restricted to)
* java (desktop, but not restricted to of course)
* js (I have a better control on this one!)

So let's forget about (rand). I'm just asking for the n%2==0 ? n/2 : -(n-1)/2
trick for seed in the stock version of Ersatz. And I won't insist and bother you
if you refuse since:
1) you're the boss,
2) I could ship a modified version of Ersatz with MicroAlg (but I'd
prefer the stock one),
or implement a generator in PicoLisp (even if it would be slow).


chri

-- 

http://profgra.org/lycee/ (site pro)
http://delicious.com/profgraorg (liens, favoris)
https://twitter.com/profgraorg
http://microalg.info
--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to