<p>You can use the &quot;sample&quot; function: <a href="https://stat.ethz.ch/R-manual/R-devel/library/base/html/sample.html" rel="nofollow noreferrer">https://stat.ethz.ch/R-manual/R-devel/library/base/html/sample.html</a></p>
<p>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 <code>c(1,1,1,1,2,2,2,2)</code></p>
<p>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:</p>
<pre><code>sample(c(1,1,1,1,2,2,2,2))
</code></pre>

CC BY-SA 4.0
2021-01-28T11:24:15.160Z
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
CC BY-SA 4.0
2021-01-28T12:25:51.513Z
@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
CC BY-SA 4.0
2021-01-31T09:55:11.840Z
@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
CC BY-SA 4.0
2021-01-26T16:16:13.470Z
2021-01-26T16:16:13.470Z
Bryan Krause
<p>I was wondering if it's possible to automatically pseudo-randomize stimuli in R? If so, I would be very grateful for any help.</p>

CC BY-SA 4.0
2021-01-25T15:59:14.020Z
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
CC BY-SA 4.0
2021-01-26T16:08:10.800Z
I was actually looking for tips on how to do that, I am sorry for not being clear.
rhododendron
<experiment-design><psycholinguistics>
Automatic pseudo-randomization of stimuli in R
rhododendron
# Automatic pseudo-randomization of stimuli in R

(Asked by: username_0 on 2021-01-25)

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

**Tags:** experiment-design, psycholinguistics

> **Comments:**
> **username_1**: 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".  
> **username_0**: I was actually looking for tips on how to do that, I am sorry for not being clear.  

---

## 1 answers

### Answer by username_1 on 2021-01-26. Score: 1

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))

> **Comments:**
> **username_0**: 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.  
> **username_1**: @username_0 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.  
> **username_2**: @username_0 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 :)  

---

