If you want to create random numbers with a custom seed without affecting Math.random, add var myrng = new edrandom(‘hello.’) to code_JS and then retrieve random numbers using myrng(). The seed generated is saved to seedString. seedString = edrandom() will seed based on current time, dom state, and other accumulated local entropy. You can then seed the random numbers by adding edrandom(“hello.”) to code_JS. a 1, 2, 3, 4 so that the order becomes completely different (the number at each position is different from the. So far I have found the Knuth Shuffle to do this in JS language: function shuffle(array) (this,Math,256,6,52,“object”=typeof module&module,“function”=typeof define&define,“random”) constants import ( NOTSTARTED, STARTED, PLAYING, PAUSED, STOPPED, FINISHED, PRESSED, RELEASED, FOREVER) import numpy as np whole numpy lib is available, prepend np. If you are interesting in another randomization script using PsychoPy click here.I am trying to replace the “random.shuffle” function so that I can upload my experiment to Pavlovia as I cannot import anything when I want to use it in Pavlovia. from psychopy import localesetup, sound, gui, visual, core, data, event, logging from psychopy. This module is called random, and is imported alone - not from psychopy. However, if you know a better method I would love to see it. Before randomisation can work, you must import the module for randomising. The script solved my problem of quazi-randomization and it is pretty quick. #We need to run again if the constrains we need is not satisfiedĮlif freq != ntrials/2 and freq !=ntrials/2 or sum(freq) !=ntrials: The last line of code call the function, with a list, and number of trials. That is, it is 50% items that are of a color and then followed by a different color? An additional check is also made to make sure that there are as many items that were required (i.e-, number of trials ntrials). That is, sometimes the randomization will fail and, therefore, the code below first checks that the wanted output has been generated. The last code snippet, below, crucial for the script to be fully functional since. NEachstim = ntrials/len(liststim) #Number of each stim is going to be evenĬountOfStim = dict((el,0) for el in stimList) Ntrials is an integer indicating number of trials Liststim.append(col + '-' + figure + '_' + figure2)īased on that each filename (of the images) starts with Black or Blue. Syntax random.shuffle ( sequence, function ) Parameter Values More Examples Example You can define your own function to weigh or specify the result. Note: This method changes the original list, it does not return a new list. Fifty percent of the items in the list are followed by a stimulus in the same colour and the remaining 50 % are followed by a stimulus in a different colour. The shuffle () method takes a sequence, like a list, and reorganize the order of the items. For this experiment, I needed a list of stimuli names that were quasi-randomized. This was written, specifically, for a psychological experiment ( a shifting/task-switching task) I was planning to conduct. Here you will find a Python function for randomization with constrains.
0 Comments
Leave a Reply. |