-
Hey all, I am trying to use jsPsych.randomization.sampleNormal function, but I get the following error: Uncaught TypeError: jsPsych.randomization.sampleNormal is not a function I am using version 6.3 Could this be because this function is introduced in a later release? I just want to do x = jsPsych.randomization.sampleNormal(mean,std); Thanks a lot ! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This function was added in version 7.1, so you would need to upgrade to use it. However, this is a pretty small function to just add to your project. This function, from this StackOverflow answer, will generate a random sample from a normal distribution with mean 0 and standard deviation 1. // Standard Normal variate using Box-Muller transform.
function randn_bm() {
var u = 0, v = 0;
while(u === 0) u = Math.random(); //Converting [0,1) to (0,1)
while(v === 0) v = Math.random();
return Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v );
} If you want to be able to set the mean and std then this will let you do that: function sampleNormal(mean, standard_deviation) {
return randn_bm() * standard_deviation + mean;
} |
Beta Was this translation helpful? Give feedback.
This function was added in version 7.1, so you would need to upgrade to use it.
However, this is a pretty small function to just add to your project. This function, from this StackOverflow answer, will generate a random sample from a normal distribution with mean 0 and standard deviation 1.
If you want to be able to set the mean and std then this will let you do that: