inkjs icon indicating copy to clipboard operation
inkjs copied to clipboard

Replace the PRNG

Open y-lohse opened this issue 7 years ago • 10 comments

Align the PRNG in inkjs with the C# version so the randomness is the same on all platforms. The C# version can be found here.

If someone with an up and running C# env wants to tackle this one, feel free to grab it!

y-lohse avatar Sep 21 '16 20:09 y-lohse

Note: I'd be very happy to use a simple-as-possible custom PRNG in C# to make ports simpler. (But prob wouldn't have time to implement it myself, but might be happy to back port if you started with a JS version?)

On 21 September 2016 at 21:03:38, Yannick Lohse ([email protected]) wrote:

Align the PRNG in inkjs with the C# version so the randomness is the same on all platforms. The C# version can be found here. http://referencesource.microsoft.com/#mscorlib/system/random.cs,bb77e610694e64ca

If someone with an up and running C# env wants to tackle this one, feel free to grab it!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/y-lohse/inkjs/issues/31, or mute the thread https://github.com/notifications/unsubscribe-auth/AA0bVyCzrElU6UQXphkgpATGFUmDtqMdks5qsY2agaJpZM4KDODk .

joethephish avatar Sep 21 '16 20:09 joethephish

Well, inkjs currently uses this one, if you want to have a look at it. They hardly come simpler than that :-)

y-lohse avatar Sep 21 '16 20:09 y-lohse

Yup, looks ideal! Let's do that then.

On 21 September 2016 at 21:17:14, Yannick Lohse ([email protected]) wrote:

Well, inkjs currently uses this one https://gist.github.com/blixt/f17b47c62508be59987b, if you want to have a look at it. They hardly come simpler than that :-)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/y-lohse/inkjs/issues/31#issuecomment-248730084, or mute the thread https://github.com/notifications/unsubscribe-auth/AA0bVwRZQLg5G-AstnAdFDXzHNkkgaWCks5qsZDKgaJpZM4KDODk .

joethephish avatar Sep 21 '16 20:09 joethephish

If you want a super simple PRNG then I'd recommend Xorshift. It usually scores better on tests than LCGs.

curiousdannii avatar Oct 03 '16 14:10 curiousdannii

@joethephish @y-lohse Is this feature still in any demand? It seems like something good I could tackle to learn more about RNG implementation.

NQNStudios avatar Jun 05 '18 03:06 NQNStudios

Not sure! I'm going to take a wild guess here and say that @joethephish would still like to switch the PRNG in ink, but is busy creating a game. Switching inkjs to the C# implementation is still an option, but I'm not sure there's really a demand for it. But if you feel like working on it, the PR would be welcome :)

y-lohse avatar Jun 05 '18 08:06 y-lohse

I'm in favour of both having a super simple/lightweight (but effective!) implementation that's the same for both. But yeah, it's not a huge priority for me, but having consistency between CS#/JS would be cool!

joethephish avatar Jun 05 '18 09:06 joethephish

I used this in an Inform project when I wanted reproducible cross platform random seeds. The third one is called xorshift* and is extremely reliable for the code size - only one word of state and 7 operations!

https://gist.github.com/Marc-B-Reynolds/0b5f1db5ad7a3e453596

I'd be happy to do up PRs for both implementations if you'd be interested.

curiousdannii avatar Jun 05 '18 15:06 curiousdannii

Sounds good to me :)

y-lohse avatar Jun 06 '18 15:06 y-lohse

It doesn't appear that nextFloat is ever used, do we need to keep it?

Hmm, could either of you help me by explaining briefly how NextSequenceShuffleIndex works?

Edit: I think I mostly understand. You're not storing the actually shuffled list, so you have to recreate it based on the hash of the container and the storyseed. That means the whole thing will change if SeedRandom is called, right?

curiousdannii avatar Jun 07 '18 02:06 curiousdannii