Replies: 5 comments
-
I think your strategy is probably the correct one. Since you want a fixed sequence, you could also generate the sequence once using the built in RNG locally, and hard code it into a custom sample function. |
Beta Was this translation helpful? Give feedback.
-
Using seedrandom was much more straight forward than I thought. It can overwrite the Math.random() function globally, if you set it like this on the first line of your jsPsych script:
The timeline then automagically becomes perfectly predictable. The seedrandom readme does state that this is insecure for any cryptography or similar use cases, but for my use case I don't think it really matters. The recommended way is to create a separate random generator:
I think it would be fairly straightforward to allow a setting in jsPsych for setting a seed in the sample functions; if set to a string, it uses Then again maybe it would be awkward to require downloading a separate library to use the seed function, what do you think? |
Beta Was this translation helpful? Give feedback.
-
Glad to hear that this works well! I've been hesitant to bundle in a separate library like this, especially for a function that would be used only occasionally. I suppose that the library is small enough that it could just be merged into jsPsych. It's MIT Licensed. On the other hand, given how easy it is to do this as you demonstrated, it may not be worth it. |
Beta Was this translation helpful? Give feedback.
-
Yeah I see your point. I'll add a little extra info here then for anyone else searching for setting a seed:
Now any sample function you use (https://www.jspsych.org/overview/timeline/#sampling-methods) will be the same every time! |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm currently using the 'fixed-repetitions' sample function, to randomize three kinds of trials an equal amount of times during 30 total trials.
I'd like the created sequence to be the same for all participants in my experiment, so I thought I could just set a random seed, but apparently that doesn't exist natively in javascript (https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript)
It looks like there's a semi standard in the js community to use this library for enabling setting a seed; https://github.com/davidbau/seedrandom
So I could use that with a custom sample function to enable what I need.
Is there some other way to achieve this with the current functionality in jsPsych that I've overlooked?
Beta Was this translation helpful? Give feedback.
All reactions