[chuck-users] "Or"

Mark Cerqueira mark.cerqueira at gmail.com
Fri Sep 3 19:15:02 EDT 2010


Hiyo,
Until likely and such get incorporated into the ChucK source, try this...

fun int likely() {
    return (maybe || maybe);   
}

fun int unlikely() {
    return (maybe && maybe);
}

It won't let you set likely or unlikely to a certain value, but as some have posted, there really is no exact value for these special words. likely() does give you a higher chance of hitting (getting true) and unlikely() has a lower chance of hitting so it does the job for me. If you want to specify how likely or unlikely something is you can also include these functions....

fun int likely(int howLikely) {
    maybe => int answer;
    
    for (0 => int i; i < howLikely; i++)
        answer || maybe => answer;
    
    return answer;
}

fun int unlikely(int howUnlikely) {
    maybe => int answer;
    
    for (0 => int i; i < howUnlikely; i++)
        answer && maybe => answer;
    
    return answer;
}

The argument passed makes the function more or less likely to return true (e.g. setting howLikely to 3 results in 93% hits, while setting howUnlikely to 3 results in 6% hits). Again, results will deviate a little over time, but I think that's desired if you're throwing words likely likely, maybe, and unlikely into your ChucK programs.

I'm attaching a file that includes these methods and tests that run these methods several times, printing out the number of hits. Sorry about the copy-and-paste abuse. Below is a transcript of the log the program prints for 100,000 trials using different variations of the above methods.

Best,
mark



RUNNING TESTS WITH 100000 TRIALS
 
"Test 1: likely()" : (string)
		% hits = 0.749730 
 
"Test 2: unlikely()" : (string)
		% hits = 0.251870 
 
"Test 3: likely(1)" : (string)
		% hits = 0.751820 
 
"Test 4: likely(2)" : (string)
		% hits = 0.876520 
 
"Test 5: likely(3)" : (string)
		% hits = 0.938420 
 
"Test 6: unlikely(1)" : (string)
		% hits = 0.248220 
 
"Test 7: unlikely(2)" : (string)
		% hits = 0.127460 
 
"Test 8: unlikely(3)" : (string)
		% hits = 0.061980 






On Sep 3, 2010, at 11:48 AM, Kassen wrote:

> Joe;
>  
> If we made 'likely' (and 'unlikely') chuckable that would make it nice:
> 
>   .70 => likely;  /* also sets 'unlikely' to .30 at the same time */
>    
> 
>  Ok, and this would be system-wide? So I could do this in one shred and have it affect others?
> 
> I quite like this idea. It's a new sort of thing, in that it would be a key-word that would act as both a variable and a function... but it's simple, intuitive and versatile. It would probably be great for live control over generative pieces with random component, where we could sort of crossfade between two kinds of behaviour.
> 
> I'd like to have this. Actually I'd like to be able to build this sort of thing myself, within ChucK.
> 
> Yours,
> Kas.
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20100903/428b29b2/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: likely.ck
Type: application/octet-stream
Size: 2156 bytes
Desc: not available
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20100903/428b29b2/attachment-0001.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20100903/428b29b2/attachment-0002.html>


More information about the chuck-users mailing list