# Automatic pseudo-randomization of stimuli in R

I was wondering if it's possible to automatically pseudo-randomize stimuli in R? If so, I would be very grateful for any help.

• Pseudo randomness is typically just a random permutation. You can write code to do this in any general language. Not sure what you mean by "automatically". – Bryan Krause Jan 25 at 15:59
• I was actually looking for tips on how to do that, I am sorry for not being clear. – rhododendron Jan 26 at 16:08

You can use the "sample" function: https://stat.ethz.ch/R-manual/R-devel/library/base/html/sample.html

Start with a list of the stimuli you want to present. For example, if you have two stimuli that should be repeated 4 times each, your list would be c(1,1,1,1,2,2,2,2)

If you take 8 samples from this distribution without replacement, you have a random permutation of the list. This is the default behavior if you just give the original list, like this:

sample(c(1,1,1,1,2,2,2,2))

• Thank you! As I understand this would not necessarily create a pseudo-randomization, but a randomization instead. I was actually wondering how to create pseudo-randomized lists in which for example the same condition cannot come up more than 3 times in a sequence. So if I example conditions a, b, c, d, the script would create patterns such as aabbccddaaabbbcccddd or similar to that. – rhododendron Jan 28 at 11:24
• @rhododendron What I write is also pseudorandom, because it's sampling without replacement. For what you describe you could do a block randomization where you take consecutive draws from a smaller number of stimuli and then stitch them together. – Bryan Krause Jan 28 at 12:25
• @rhododendron could you give us more details on what the constrains are and how long the sequence should be? Maybe we could then give a more fitting reply :) – bucky Jan 31 at 9:55