[chuck-users] (casting) in chuck?

Adam Tindale adamtindale at hotmail.com
Mon Sep 3 13:13:32 EDT 2007

Hey Jochen,

Std.rand() gives you a random int.
Std.rand2(int min, int max) gives you an int between min and max.

When I changed rand() to rand2() everything worked just fine for me.

Eduard's solution is nice because he just sidestepped the casting. Also,
notice that he disconnects the ugen with the unchuck operator. Nice form.

Happy ChucKing.


JH wrote:
>thanks, that does work. Not sure what i was doing wrong...
>- j
>eduard aylon wrote:
>>Hi Jochen,
>>don't know what's wrong with your code, but the following works for me:
>>UGen u[2];
>>SinOsc s @=> u[0];
>>SawOsc w @=> u[1];
>>0 => int i;
>>while( true )
>>      u[i&1] => dac; // connect one osc
>>      u[1-(i&1)] =< dac; // disconnect the other one
>>      i++;
>>      1000::ms => now;
>>hope this helps,
>>On Aug 31, 2007, at 7:00 PM, Jochen Hartmann wrote:
>>>I am total newbie to chucK. been trying to make time to play with  it 
>>>more ever since last year but somehow that time didnt arrive  until now.
>>>So for today's silly question I was wondering if there is some kind  of 
>>>implicit casting of objects in chuck?
>>>For instance I want to fill an array with specific UGens and then  
>>>randomly retrieve one like so:
>>>//array of UGens
>>>UGen items[2];
>>>SinOsc sin @=> items[0];
>>>SawOsc saw @=> items[1];
>>>//later in my loop
>>>Std.rand(0,1) => int item;
>>>items[item] @=> UGen mysteryOscillator;
>>>mysteryOscillator => dac;
>>>Obviously this is not working right now and I am wondering if I am  doing 
>>>something wrong syntactically or whether I am trying to do  something 
>>>that ChucK can't do.
>>>thanks for the help !
>>>- j
>>>chuck-users mailing list
>>>chuck-users at lists.cs.princeton.edu
>>chuck-users mailing list
>>chuck-users at lists.cs.princeton.edu
>chuck-users mailing list
>chuck-users at lists.cs.princeton.edu

Former Police Officer Paul Gillespie’s TAKE BACK THE INTERNET tips and 
tricks, watch the video now  http://safety.sympatico.msn.ca/

More information about the chuck-users mailing list