cross-platform random seeding would be nice

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

cross-platform random seeding would be nice

Raoul Duke
hi,

cf. e.g. http://haxe.1354130.n2.nabble.com/random-numbers-td2744037.html

i'd like to use Math.random() but i'd like to be able to re-seed it,
to replay #s.

sincerely.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: cross-platform random seeding would be nice

Franco Ponticelli
There is such function in thx: http://code.google.com/p/thx-core/source/browse/src/thx/math/Random.hx

Franco

On Sun, Sep 11, 2011 at 2:58 PM, Raoul Duke <[hidden email]> wrote:
hi,

cf. e.g. http://haxe.1354130.n2.nabble.com/random-numbers-td2744037.html

i'd like to use Math.random() but i'd like to be able to re-seed it,
to replay #s.

sincerely.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: cross-platform random seeding would be nice

Nicolas Cannasse
In reply to this post by Raoul Duke
Le 11/09/2011 15:58, Raoul Duke a écrit :
> hi,
>
> cf. e.g. http://haxe.1354130.n2.nabble.com/random-numbers-td2744037.html
>
> i'd like to use Math.random() but i'd like to be able to re-seed it,
> to replay #s.

You could write a PNRG implementation in haXe, and make sure that it
overflow the same on all platforms. After, that's a speed/periodicity issue.

Best,
Nicolas


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: cross-platform random seeding would be nice

Raoul Duke
In reply to this post by Franco Ponticelli
On Sun, Sep 11, 2011 at 7:10 AM, Franco Ponticelli > There is such function in
> thx: http://code.google.com/p/thx-core/source/browse/src/thx/math/Random.hx

thanks!

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: cross-platform random seeding would be nice

Yanis Benson
In reply to this post by Raoul Duke

Please, consider looking into https://github.com/stroncium/hx-various FastRNG class. The main priorities were the ability to reseed and to generate values fast. The github version is flash-only, but the sources I use now are cross-platform and with additional shortcuts which are very useful when you do lots of randomization. Also, it has methods for generating almost anything you may want to generate without additional math, like float between two values, or bool or bool with custom chance. Overall idea is the same, so you can look into github version right now. And if you are interested I can put some polish onto my code and update it.

On 11 Sep 2011 17:59, "Raoul Duke" <[hidden email]> wrote:

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: cross-platform random seeding would be nice

Raoul Duke
hi,

what i'm looking for is:

(a) ability to seed so i can replay.
(b) identical behaviour across platforms, ha ha i laugh at myself.
* presumably depends on int-to-floating point math across platforms?
the consistency is important to me, though, like i'd be willing to do
the moral equivalent of float randFloat = cast sprintf( "%d.%d",
randInt(), randInt() ) if it gets me the same floats everywhere.
* presumably means using lowest common denominator sizes of things
across the platforms, like 31 bits of signed ints from neko.
(c) faster rather than statistically / cryptographically safe.

:-)

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: cross-platform random seeding would be nice

Nicolas Cannasse
Le 11/09/2011 16:40, Raoul Duke a écrit :
> hi,
>
> what i'm looking for is:
>
> (a) ability to seed so i can replay.
> (b) identical behaviour across platforms, ha ha i laugh at myself.
> * presumably depends on int-to-floating point math across platforms?

Std.int, Math.floor and Math.ceil are reliable. Math.round might not be
but I think it is.

Other calculus are compatible as long as your platform use double
(IEEE64) FP calculus.

Best,
Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: cross-platform random seeding would be nice

Yanis Benson
In reply to this post by Raoul Duke

Ok, I'll update my code. It currently uses Int32 for neko though. And yes, it's replayable, fast and not cryptographically safe.

On 11 Sep 2011 18:41, "Raoul Duke" <[hidden email]> wrote:
> hi,
>
> what i'm looking for is:
>
> (a) ability to seed so i can replay.
> (b) identical behaviour across platforms, ha ha i laugh at myself.
> * presumably depends on int-to-floating point math across platforms?
> the consistency is important to me, though, like i'd be willing to do
> the moral equivalent of float randFloat = cast sprintf( "%d.%d",
> randInt(), randInt() ) if it gets me the same floats everywhere.
> * presumably means using lowest common denominator sizes of things
> across the platforms, like 31 bits of signed ints from neko.
> (c) faster rather than statistically / cryptographically safe.
>
> :-)
>
> --
> haXe - an open source web programming language
> http://haxe.org

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: cross-platform random seeding would be nice

Nicolas Cannasse
Le 11/09/2011 17:55, Yanis Benson a écrit :
> Ok, I'll update my code. It currently uses Int32 for neko though. And
> yes, it's replayable, fast and not cryptographically safe.

You can also use & 0x3FFFFFFF to be neko-compatible.

Best,
Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: cross-platform random seeding would be nice

Yanis Benson
In reply to this post by Raoul Duke

My idea was to have exactly same sequences on all platforms. But I guess I should add the switch for that.
Also, I had random selector with custom probabilities class somewhere. Maybe I should start haXe random library. Basically, this plus mersen twister will suit the tastes of most people in randomization field.

On 11 Sep 2011 20:04, "Nicolas Cannasse" <[hidden email]> wrote:

--
haXe - an open source web programming language
http://haxe.org