Random -copy-paste work around

caseyfarina's picture

What is the best way (or your way) to work around the fact that QC copies the same seed when a random controller is copied?

It is really unsustainable to drag in a new instance of "random controller" for large patches and macros.

Thanks, this forum is a great resource, First time poster long time reader.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

cwright's picture
unsanity

This DRIVES ME INSANE as well! :) I'm glad I'm not alone in this.

As far as I know, there's no workaround. We might be able to modify the inspector panel to add this sort of thing though.. not sure how that would work, exactly. There are some other alternatives as well (code-wise, not really UI-wise).

toneburst's picture
JavaScript

The JavaScript Math.random() function is a potential alternative to the QC random patch. The JS method seems to work fine inside an Iterator, too, unlike the buildin random source.

a|x

toneburst's picture
Talking of Math.random()...

...is it likely to be quicker to generate a list of random values using a single JS script and passing them in to an Iterator as a structure, or to use a JS script inside the Iterator to do a similar job?

a|x

caseyfarina's picture
I'm not very knowledgeable

I'm not very knowledgeable in the javascript area, what is the simplest piece of code to generate random numbers?

I'm coming from more of a Max/MSP background, and would love a random ramps (like line or line~ in MSP) that generates a new ramp each time one is completed.

I suppose this could use the interpolation patch and a random object that generates new values only at the end of a ramp. Any suggestions?

smokris's picture
Some JavaScript Math.random() examples

Constant Random

The following JavaScript code will generate a single (constant) random value between 0 and 1:

function (__number Value) main()
{
   var result = new Object();
   result.Value = Math.random();
   return result;
}

If you cut-and-paste this JavaScript patch, each instance will generate a different constant random number.

Varying Random

If you want the random number to change with every frame, use the following code:

function (__number Value) main(__number PatchTime)
{
   var result = new Object();
   result.Value = Math.random();
   return result;
}

...and connect a Patch Time to the JavaScript patch's input. (This forces the JavaScript code to reevaluate for each frame, whereas without the Patch Time input, the JavaScript code is only evaluated during the first frame.)

Linear-Interpolated Random Values

For something like what caseyfarina described in the above comment, try this code:

var result = new Object();
 
function (__number Value,__number TargetValue,__number Duration) main(__number PatchTime,__number ValueMin,__number ValueMax,__number DurationMin,__number DurationMax)
{
   if( _testMode )
      result.FirstFrame = true;
 
   if( !_testMode && ( result.FirstFrame || PatchTime - result.StartedOn > result.Duration ) )
   {
      if( result.FirstFrame )
      {
         result.Value = ValueMin;
         result.FirstFrame = false;
      }
 
      result.TargetValue = Math.random() * (ValueMax-ValueMin) + ValueMin;
      result.Duration = Math.random() * (DurationMax-DurationMin) + DurationMin;
      result.Velocity = (result.TargetValue-result.Value)/result.Duration;
      result.StartedOn = PatchTime;
      result.LastTime = PatchTime;
   }
 
   delta = PatchTime - result.LastTime;
   result.Value += result.Velocity*delta;
   result.LastTime = PatchTime;
 
   return result;
}

and see the attached composition.

PreviewAttachmentSize
JavaScriptLinearInterpolation.qtz5.74 KB

caseyfarina's picture
A thousand thanks

Smokris is the Man, Seriously thanks that last patch is exactly what I've been trying to build in QC. That is going to save lots of work. Indeed a great work around. Thanks again, Casey