# Round robin or random script



## Freesamples (Mar 25, 2009)

Hello!

I want to make a free bass sample library with 4 layers on each velocity level. And I have a question. Is it possible to make round robin random script?

I'll try to explain. Round robin is playing sample in constant cycle, that is 1, 2, 3, 4 and again 1, 2, etc.. But I need something like this 1, 2, 3, 4, 2, 1, 4, 3, 2, 4, 1 etc.. Of course you can recommend me to use Random cycle, but in Random cycle one group can be played 2 or more times in succession and it does not correspond to my idea.

So I need script to playing groups randomly, on condition that one group cannot be played 2 or more times in succession.

Please help me.

Here you can download test version of bass with one note and 4 round robin groups: http://www.mediafire.com/?sharekey=5...4e75f6e8ebb871


----------



## Thonex (Mar 25, 2009)

http://www.vi-control.net/forum/viewtopic.php?t=3457


----------



## mbietenholz (Mar 25, 2009)

Actually, you don't need a script to do round robin, Kontakt does that without scripts. Its in the "group triggering" options. OOps, sorry, I misread, you're right to do random w/o repeats you do need a script.

never mind....


----------



## kotori (Mar 25, 2009)

mbietenholz @ Wed Mar 25 said:


> Actually, you don't need a script to do round robin, Kontakt does that without scripts. Its in the "group triggering" options. Basically, for each group, you decide where in the round-robin chain it will be
> and you're away.


Yes, but in order to do full-cycle random-order RR one needs a script.


----------



## Thonex (Mar 25, 2009)

kotori @ Wed Mar 25 said:


> mbietenholz @ Wed Mar 25 said:
> 
> 
> > Actually, you don't need a script to do round robin, Kontakt does that without scripts. Its in the "group triggering" options. Basically, for each group, you decide where in the round-robin chain it will be
> ...



Hi Nils,

By full cycle rnd, do you mean that the each group (in the robin) would have to be played once (and only once) before beginning another cycle? Because i think he was only interested in just having groups not repeat twice in a row.

And... if you DID mean the former... do you have a clever formula for that? :D 

for a 4 group "Full Cycle RND"... there aren't that many possibles... it might be easier to just make a table and intelligently but randomly chose between the tables?

for example... these are all the possibilities for a 4 x RND RR Cycle starting with "1":

1234
1243
1324
1342
1423
1432

Maybe just using the above with some sort of mod 4 addition to a non sequential RND number?

T


----------



## kotori (Mar 25, 2009)

Thonex @ Wed Mar 25 said:


> Hi Nils,
> 
> By full cycle rnd, do you mean that the each group (in the robin) would have to be played once (and only once) before beginning another cycle? Because i think he was only interested in just having groups not repeat twice in a row.



Aha. Here's a script I quickly put together that does this:

```
on init
  declare $rr
  declare $previous_rr
end on

on init
  while ($rr = $previous_rr)
    $rr := random(0, 3)   { one of the first four groups (one starts counting from zero rather than one) }
  end while
  $previous_rr := $rr
  
  disallow_group($ALL_GROUPS)
  allow_group($rr)    
end on
```



> And... if you DID mean the former... do you have a clever formula for that? :D


Well, a simple solution is to shuffle an array and do this in a while loop until the first element does not constitute a repetition of the last group used. Here are two functions which can come in handy:
*function* swap(a, b)
``*declare* tmp
``tmp := a
``a := b
``b := tmp
*end function*

*function* shuffle_array(array)
``*declare* i``
``*declare* j
``*for* i := 0 *to* num_elements(array)-1
````j := random(0, num_elements(array)-1)
````swap(array_, array[j])
``*end for*
*end function*__

Good point about the table. Here's a template script using that approach (I guess Group 1 will always be spaced equally in this approach though):


Code:


on init
  declare %table[24] := (1,2,3,4,  1,2,4,3,  1,3,2,4,  1,3,4,2,  1,4,2,3,  1,4,3,2)
  declare $i                       
end on

on note
  inc($i)
  if ($i mod 4 = 0)
    $i := random(0, 5) * 4
  end if  
  message("cycle #" & $i/4 & " index=#" & $i & " group=#" & %table[$i])
end on

_


----------



## Thonex (Mar 25, 2009)

Wow... thanks Nils!!! :D 



kotori @ Wed Mar 25 said:


> Good point about the table. Here's a template script using that approach (I guess Group 1 will always be spaced equally in this approach though):



No necessarily... if you revise the numbers to be 0123, 0132, etc... you can choose a random number 1-4 and just create a new array based on your new RND starting number then mod 4. We'd just need to make sure the new RND starting number was not the same as the 4th array number.

One day when I have some time... I'll write it and òãÔ   šc\ãÔ   šc]ãÔ


----------



## Freesamples (Mar 26, 2009)

Thanks Nils!!! Thanks Thonex! Thanks all...

Cool forum


----------

