y-lohse / inkjs

A javascript port of inkle's ink scripting language.
http://www.inklestudios.com/ink/
MIT License
508 stars 104 forks source link

Replace the PRNG #31

Open y-lohse opened 8 years ago

y-lohse commented 8 years ago

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!

joethephish commented 8 years ago

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 (notifications@github.com) 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 .

y-lohse commented 8 years ago

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

joethephish commented 8 years ago

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

On 21 September 2016 at 21:17:14, Yannick Lohse (notifications@github.com) 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 .

curiousdannii commented 8 years ago

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

NQNStudios commented 6 years ago

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

y-lohse commented 6 years ago

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 :)

joethephish commented 6 years ago

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!

curiousdannii commented 6 years ago

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.

y-lohse commented 6 years ago

Sounds good to me :)

curiousdannii commented 6 years ago

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?