# Randomizing Different Subsets of Stimuli from an Excel File with Text Response in between

**URL:** <https://discourse.psychopy.org/t/randomizing-different-subsets-of-stimuli-from-an-excel-file-with-text-response-in-between/35972>\
**Category:** Builder\
**Tags:** randomization, textbox\
**Created:** [August 2, 2023, 5:29pm UTC](https://discourse.psychopy.org/t/randomizing-different-subsets-of-stimuli-from-an-excel-file-with-text-response-in-between/35972 "2023-08-02T17:29:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fizban137](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/fizban137/32/38969_2.png) [@Fizban137](https://discourse.psychopy.org/u/Fizban137)\
**Post date:** [August 2, 2023, 5:29pm UTC](https://discourse.psychopy.org/t/randomizing-different-subsets-of-stimuli-from-an-excel-file-with-text-response-in-between/35972/1 "2023-08-02T17:29:40Z")

</div>

If this template helps then use it. If not then just delete and start from scratch.

**OS** (e.g. Win10): Windows 11 Pro  
**PsychoPy version** (e.g. 1.84.x): Psychopy 2023 -1.3.  
**Standard Standalone? (y/n)** If not then what?: Yes  
**What are you trying to achieve?:**  
I have 42 sentences in an Excel file that I inserted in a routine on PsychoPy. My participants will read each sentence (one at a time) and judge whether the sentence is meaningful with a key press. In every 2, 3, 4, or 5 sentences, they need to write down the last words of the sentences they have read so far. The 2-, 3-, 4- or 5-sentence sequences should be randomized. The sentences in the sets should also be randomized and each sentence should appear only once until all 42 are shown.

To summarize using the image below, I need my stimuli\_experiment routine (or a possible loop there) to pick random sentences from a pool of 42 sentences (which I have inserted in the routine with an Excel file9 in sets of 2, 3, 4 or 5, and the text\_resp routine should randomly interfere in every 2,3,4 or 5 sentences to demand a text response.

![psychopy](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/b/2/b23145f3c1f1712833612f17a634755850d3dd27.jpeg)

**What did you try to make it work?:**  
I tried some stuff from the builder menus but could not manage it. I then picked random sentences for 3 sets of 2,3,4 and 5 sentences (42 in total), inserted them in different routines (quite impractical I know), surrounded each routine and a text response with a loop and added an overarching loop that surrounds all routines but it took me nowhere. I’m stuck as of now, and help would be appreciated.

**What specifically went wrong when you tried that?:**  
My loop strategy did not randomize the order of routines. This is my secondary solution by the way, my first aim is to randomly present 2,3,4 and 5 sentence sets using a loop or randomization, not inserting them in separate routines and trying to move them around.

Thanks in advance.  
Include pasted full error message if possible. “That didn’t work” is not enough information.

---

<div class="post-metadata">

**Author:** ![suelynnmah](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@suelynnmah](https://discourse.psychopy.org/u/suelynnmah)\
**Post date:** [August 4, 2023, 11:03am UTC](https://discourse.psychopy.org/t/randomizing-different-subsets-of-stimuli-from-an-excel-file-with-text-response-in-between/35972/2 "2023-08-04T11:03:17Z")

</div>

Hi, based on my understanding of your task, I’ve made a minimal demo that should do the trick. Hope this helps 🙂  
[multi sentence blocks.zip](https://discourse.psychopy.org/uploads/short-url/cD2R0bl2WkQi3N0p4QsIRAx7BWU.zip) (26.7 KB)

---

<div class="post-metadata">

**Author:** ![Fizban137](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/fizban137/32/38969_2.png) [@Fizban137](https://discourse.psychopy.org/u/Fizban137)\
**Post date:** [August 4, 2023, 11:35am UTC](https://discourse.psychopy.org/t/randomizing-different-subsets-of-stimuli-from-an-excel-file-with-text-response-in-between/35972/3 "2023-08-04T11:35:56Z")

</div>

Hi Sue, thanks a lot for the great effort. You managed to solve the biggest problem of mine with what you just suggested. I also needed sets of 5 but I think I can manage that with an Excel file and proper additions to the loops. It is also possible to randomly pick those 2, 3 ,4 and 5 sentences from my stimuli pool of 42 sentences right? That is exactly what I need. To clarify, I need the 2,3,4,5 sentence files/loops to randomly pick sentences from the pool until all 42 sentences are shown once but not more.

---

<div class="post-metadata">

**Author:** ![suelynnmah](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@suelynnmah](https://discourse.psychopy.org/u/suelynnmah)\
**Post date:** [August 4, 2023, 12:31pm UTC](https://discourse.psychopy.org/t/randomizing-different-subsets-of-stimuli-from-an-excel-file-with-text-response-in-between/35972/4 "2023-08-04T12:31:03Z")

</div>

Ahhh the current implementation doesn’t allow that. I’ve tweaked the demo with the relevant code components to achieve what you’re wanting  
[multi sentence blocks 2.zip](https://discourse.psychopy.org/uploads/short-url/5QYRMuNSztUS3da7dPmFlYmlOY4.zip) (16.0 KB)

---

<div class="post-metadata">

**Author:** ![Fizban137](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/fizban137/32/38969_2.png) [@Fizban137](https://discourse.psychopy.org/u/Fizban137)\
**Post date:** [August 4, 2023, 3:36pm UTC](https://discourse.psychopy.org/t/randomizing-different-subsets-of-stimuli-from-an-excel-file-with-text-response-in-between/35972/5 "2023-08-04T15:36:08Z")

</div>

Wow this work exactly as I wanted, I had different response options in mind but I can handle it thanks a lot you’ve been a huge help

---

<div class="post-metadata">

**Author:** ![Fizban137](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/fizban137/32/38969_2.png) [@Fizban137](https://discourse.psychopy.org/u/Fizban137)\
**Post date:** [August 6, 2023, 9:33pm UTC](https://discourse.psychopy.org/t/randomizing-different-subsets-of-stimuli-from-an-excel-file-with-text-response-in-between/35972/6 "2023-08-06T21:33:19Z")

</div>

Hello again, is it possible to tweak the code or the logic a little more so that I can see which sentences were shown to the participants in the excel data? I tried adding correct answer information to the loops and stuff but it disrupted the randomization of text response and sentences.

---

<div class="post-metadata">

**Author:** ![suelynnmah](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@suelynnmah](https://discourse.psychopy.org/u/suelynnmah)\
**Post date:** [August 7, 2023, 10:14am UTC](https://discourse.psychopy.org/t/randomizing-different-subsets-of-stimuli-from-an-excel-file-with-text-response-in-between/35972/7 "2023-08-07T10:14:39Z")

</div>

Yes if you add line 9, this would save the sentences in a column called sentence\_shown in the csv output

![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/d/2/d209dea180256a727a7835932e4408b38dd1a6ce.png)

---

<div class="post-metadata">

**Author:** ![Fizban137](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/fizban137/32/38969_2.png) [@Fizban137](https://discourse.psychopy.org/u/Fizban137)\
**Post date:** [August 7, 2023, 11:55am UTC](https://discourse.psychopy.org/t/randomizing-different-subsets-of-stimuli-from-an-excel-file-with-text-response-in-between/35972/8 "2023-08-07T11:55:44Z")

</div>

It worked, thanks a lot for the rescue again. I appreciate it.
