# How to randomize order with certain set of rules?

**URL:** <https://qa.fmod.com/t/how-to-randomize-order-with-certain-set-of-rules/18380>\
**Category:** FMOD Studio\
**Created:** [February 19, 2022, 2:15pm UTC](https://qa.fmod.com/t/how-to-randomize-order-with-certain-set-of-rules/18380 "2022-02-19T14:15:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![StepanSo](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/stepanso/32/3179_2.png) [@StepanSo](https://qa.fmod.com/u/StepanSo)\
**Post date:** [February 19, 2022, 2:15pm UTC](https://qa.fmod.com/t/how-to-randomize-order-with-certain-set-of-rules/18380/1 "2022-02-19T14:15:38Z")

</div>

Any advice on how to create an environment in FMOD where “chunks” (short phrases of 3-8 seconds) of a musical piece are played randomly, but with a specific set of rules/limitations?

For example: chunk A only plays when entering the zone.  
After chunk E play only L, O or R  
Every 5th chunk should repeat itself 3-4 times

I was able to figure a working “set of rules” by emulating different scenarios via Arranger chains in Cubase, but have no clue how to approach this in FMOD.

Any tips appreciated!

---

<div class="post-metadata">

**Author:** ![Alcibiade](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/alcibiade/32/4284_2.png) [@Alcibiade](https://qa.fmod.com/u/Alcibiade)\
**Post date:** [February 19, 2022, 9:41pm UTC](https://qa.fmod.com/t/how-to-randomize-order-with-certain-set-of-rules/18380/2 "2022-02-19T21:41:59Z")

</div>

There’s unfortunately no simple way to do that in FMOD. Firstly your logic is too complicated to be implemented in FMOD, secondly FMOD lacks a good way to link a chunk after another just finished. The only tools which are able to execute something after something else has just finished are the action sheet and the multi instrument. However, both will lack options you’ll need.

The only thing that would work would be to keep the logic in the game code, and drive a labelled parameter which will indicate the next chunk to play to FMOD. In FMOD, it will look like this :  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/2/245ada74a426f18cd1890f11808c0036fdabcd51.png)  
So a lot of work to configure all this… But once done for a chunk, you can copy/paste all the green transitions from chunk to chunk.

---

<div class="post-metadata">

**Author:** ![StepanSo](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/stepanso/32/3179_2.png) [@StepanSo](https://qa.fmod.com/u/StepanSo)\
**Post date:** [February 20, 2022, 11:21am UTC](https://qa.fmod.com/t/how-to-randomize-order-with-certain-set-of-rules/18380/3 "2022-02-20T11:21:29Z")

</div>

Hi Alcibiade, thanks for the suggestion! I have a strong academic music background, but unfortunately I don’t have any experience with coding, so I’m not even sure where to begin 😅

---

<div class="post-metadata">

**Author:** ![Alcibiade](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/alcibiade/32/4284_2.png) [@Alcibiade](https://qa.fmod.com/u/Alcibiade)\
**Post date:** [February 20, 2022, 1:39pm UTC](https://qa.fmod.com/t/how-to-randomize-order-with-certain-set-of-rules/18380/4 "2022-02-20T13:39:37Z")

</div>

So I assume your project isn’t for a game? Don’t you have a teammate which could do the scripting part?

---

<div class="post-metadata">

**Author:** ![StepanSo](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/stepanso/32/3179_2.png) [@StepanSo](https://qa.fmod.com/u/StepanSo)\
**Post date:** [February 20, 2022, 2:24pm UTC](https://qa.fmod.com/t/how-to-randomize-order-with-certain-set-of-rules/18380/5 "2022-02-20T14:24:30Z")

</div>

The project is for a finished sandbox game, which in turn is for my diploma thesis. I used a piece by Debussy (“Untitled Goose Game” Hommage, but I used “Epigraphes” instead of the preludes) and separated it in phrases.

Here’s how my “simulated” situation looks like in Cubase: [Theater Debussy ver13 2022 02 20 15 17 07 - YouTube](https://youtu.be/CcFbf-z5Ccc)

---

<div class="post-metadata">

**Author:** ![Alcibiade](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/alcibiade/32/4284_2.png) [@Alcibiade](https://qa.fmod.com/u/Alcibiade)\
**Post date:** [February 21, 2022, 12:20pm UTC](https://qa.fmod.com/t/how-to-randomize-order-with-certain-set-of-rules/18380/6 "2022-02-21T12:20:04Z")

</div>

What’s your game engine?

---

<div class="post-metadata">

**Author:** ![StepanSo](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/stepanso/32/3179_2.png) [@StepanSo](https://qa.fmod.com/u/StepanSo)\
**Post date:** [February 21, 2022, 1:42pm UTC](https://qa.fmod.com/t/how-to-randomize-order-with-certain-set-of-rules/18380/7 "2022-02-21T13:42:57Z")

</div>

Unreal Engine 4.26, the Sandbox Game is based on this: [The Theater - Elias Software](https://eliassoftware.com/the-theater/)

---

<div class="post-metadata">

**Author:** ![Alcibiade](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/alcibiade/32/4284_2.png) [@Alcibiade](https://qa.fmod.com/u/Alcibiade)\
**Post date:** [February 22, 2022, 11:21pm UTC](https://qa.fmod.com/t/how-to-randomize-order-with-certain-set-of-rules/18380/8 "2022-02-22T23:21:54Z")

</div>

I might be able to help you a bit with the scripting in UE4 (using blueprints). PM me if you want.

---

<div class="post-metadata">

**Author:** ![joseph](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/joseph/32/264_2.png) [@joseph](https://qa.fmod.com/u/joseph)\
**Post date:** [February 23, 2022, 2:35am UTC](https://qa.fmod.com/t/how-to-randomize-order-with-certain-set-of-rules/18380/9 "2022-02-23T02:35:14Z")

</div>

As Alcibiade says, there’s no easy way to do this in FMOD Studio. You could theoretically achieve the behavior you describe using a complex arrangement of transition and destination markers and multiple duplicates of every chunk laid out along the timeline, but the resulting event would almost certainly be complex and unwieldy to the point of being unfeasible to tweak or maintain.

You would be much better off offloading some of the logic to your game project’s code.
