Random numbers from a pool of numbers.

Discuss Lemur and share techniques.

Random numbers from a pool of numbers.

Postby f10 » 09 Nov 2017 13:42

Hey everyone,

A quick question, I'm sending CC message from a StepSlider. I have 37 values possible for each slide. I'm looking for a way to randomize a selection of values. So for example I would need the values {3, 10, 15, 20}
to be randomized across the sliders on a button press Then on the next button press it would be {10, 20, 3, 15}.
I've managed to randomize the sliders on one hand and to apply a selected pool of values on another hand, but can't figure out yet how to link the two.

If anyone has an idea, I'm all ears :)

Thanks all.
f10
Newbie
 
Posts: 6
Joined: 18 Oct 2017 11:40

Re: Random numbers from a pool of numbers.

Postby MrCorba » 09 Nov 2017 16:26

This can be done with a very simple shuffle "algorithm"

Code: Select all
// Values is the array of values to be shuffled
decl index = sizeof(values); // Get the index of the last element
decl random, temp;

while (0 != index) { // Loop until every element has passed this loop
   random = floor(rand() * index); // Create a random index
   index--; // Decrease the current index

   temp = values[index]; // Store the value add 'index' in a temp value
   values[index] = values[random]; // Set the value add the random index in the 'index' slot
   values[random] = temp; // Insert the stored value in the random slot
}

return values; // Return the values


I hope my comments make the thing a bit clearer. I've attached a sample file so you can see the implementation

And as always, just let me know if you don't understand anything;)
Attachments
shuffle.jzml
(4.32 KiB) Downloaded 12 times
"Having no silence in music is like having no black or white in a painting" - Brian Eno
https://soundcloud.com/mrcorba
MrCorba
Regular
 
Posts: 143
Joined: 02 Sep 2013 20:17
Location: Netherlands

Re: Random numbers from a pool of numbers.

Postby Phil999 » 09 Nov 2017 21:47

thanks.
Formant+Eurorack, PPG wave 2.2, Korg MS-20, etc., EWI 4000s, QuNeo, etc., Mixbus32c, u-he, MadronaLabs, Samplemodeling, NI, etc., iPad2/4/Pro
Phil999
Regular
 
Posts: 923
Joined: 11 Jan 2012 01:53

Re: Random numbers from a pool of numbers.

Postby f10 » 10 Nov 2017 05:03

Nice one MrCobra - it does the trick spot on!

I must says I'm not getting the all concept yet but I'm studying it to understand what's going on exactly:)

thanks a ton!

Cheers
f10
Newbie
 
Posts: 6
Joined: 18 Oct 2017 11:40


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 4 guests

cron