Beispiel #1
0
    def randImage(self):
        randCateg = rb(len(self.categs) - 1)
        randSubcat = rb(len(self.categs[randCateg]) - 1)
        randIm = choice(self.categs[randCateg][randSubcat])
        return randIm


#cats = Categories(2,6)
#gris = Image.open(cats.graySquare)

#encod = cats.EnStims
#recstms = cats.recStims
#trials = cats.trialslist
Beispiel #2
0
 def randImage(self):
     """
     Returns a random image path (type = str) from self.categs
     Used to select stimuli for the task
     ...
     
     Variables
     ----------
     randCateg: type = int
         Index of random image category in 'self.categs'
     
     randSubcat: type = int
         Index of random image subcategory in 'self.categs[randCateg]'
     ...
     
     Return
     ------
     randIm: type = str
         Randomly selected image path (string) from 'self.categs'
     """
     randCateg = rb(len(self.categs) - 1)
     randSubcat = rb(len(self.categs[randCateg]) - 1)
     randIm = choice(self.categs[randCateg][randSubcat])
     return randIm
Beispiel #3
0
def randInsert(lst, item):
    """Insert item to random index in lst
    ...
    
    Description
    -----------
    Inserts 'item' (can be any variable a list can contain)
    in 'lst' (a list) at a random index generated by 
    secret.ranbelow() module imported as rb.
        -cryptographically secure random values 
    
    The advantage of using this method over using built-in
    list .insert() method is that randInsert() returns a
    new list containing all items (from 'lst'+'item'),
    while .insert() returns None. This makes it harder to
    keep track of all images at any moment during experiments.
    ...
    
    Parameters:
        lst: list object
        item: any type variable
    ---------------------------
    Variables:
        sliceIndex: type = int
            A randomly generated integer where lst is sliced
        lstTop: type = list
            Upper slice of lst (from lst[0] to lst[sliceIndex])
            'item' will be appended to lstTop after lstTop[sliceIndex].
            'lstBottom' will be appended to lstTop after lstTop[item].
        lstBottom: type = list
            Lower slice of lst (from lst[sliceIndex] to lst[len(lst)-1])
            Will be appended to 'lstTop' after lstTop[item].
            
    ----------------------------------
    Return:
        newlst: unidimensional list
            Calls flatten(lst) to vectorize 'lstTop'
            see <help(flatten)> for more details
    """
    sliceIndex = rb(len(lst) - 1)
    lstTop, lstBottom = lst[:sliceIndex], lst[sliceIndex:]
    lstTop.append(item)
    lstTop.append(lstBottom)
    newlst = flatten(lstTop)
    return newlst
Beispiel #4
0
def seed_deck(card_deck):
    '''
    Description:
        Randomize cards
    Expects:
        card_deck: (list) all cards in a particular order.
    Reutrns:
        cd: (list) all cards after randomization. 
    '''    
    
    cd=[]
    for card in card_deck:
        v=tuple(card.split())
        cd.append(Card(v[0],v[1]))
    
    deck_size = len(cd)
    for i in range(SHUFFLE_COUNT):
        for element in range(deck_size):
            swap_element=rb(deck_size)
            cd[swap_element], cd[element] = cd[element], cd[swap_element]
    return cd
Beispiel #5
0
def randSign():#randomly generates 1 or -1 (quadrant position)
    if rb(2) == 0:
        return 1
    else:
        return -1