Csound Csound-dev Csound-tekno Search About

A bit off topic->score generation

Date1999-07-24 18:51
FromTobiah
SubjectA bit off topic->score generation
Please forgive if this is not interesting.

The perl code below is a boiled down version
of a program that wants to make a burst of notes
which is dense at first, and then gets lighter.
Much like the pattern that comes out of a spray
paint can held at an angle to the surface.

Braving the exposure of my stupidity, I am asking,
why does the first piece of code produce linear
results, while the second produces the desired effect?

Thanks,

Toby


--------------------------------------------------------

#!/usr/bin/perl

for($x = 0; $x < 30; ++$x){
        $it  = 100 * rand * rand * rand;
        print "It is $it\n";
}

print "XXXXXXXXXX\n";

for($x = 0; $x < 30; ++$x){

        $it = 100;
        $it *= rand;
        $it *= rand;
        $it *= rand;

        print "It is $it\n";
}

-------------------------------------------------------

It is 14.4036914221942
It is 64.0403301455081
It is 92.0018395874649
It is 86.0313134733588
It is 94.1714564803988
It is 28.7829398643225
It is 4.56200079061091
It is 52.9926896095276
It is 12.277115136385
It is 65.0413279421628
It is 7.03556826338172
It is 58.5801591631025
It is 43.5281078331172
It is 64.0121327247471
It is 58.7811752222478
It is 24.898499250412
It is 30.1713058259338
It is 69.1552561242133
It is 43.1361183989793
It is 44.8441555257887
It is 6.85915164649487
It is 66.7636311613023
It is 56.5284450538456
It is 47.2567927092314
It is 76.6749755479395
It is 30.751428892836
It is 75.7148835342377
It is 22.4481104407459
It is 45.5015169922262
It is 30.3448522929102
XXXXXXXXXX
It is 0.76186388394069
It is 21.3483627110067
It is 34.4190002005938
It is 0.130956948373957
It is 0.239052579001631
It is 1.3333306923856
It is 16.7682933320958
It is 33.6714633776643
It is 25.1988224999129
It is 56.3710418350352
It is 0.614277701366594
It is 34.1737601536983
It is 0.581045287377612
It is 19.6711942362409
It is 4.92022134523882
It is 2.09921444154036
It is 3.04495186204821
It is 2.59705455484509
It is 37.7499712346738
It is 17.5143909592512
It is 14.5600427698617
It is 34.2413973866594
It is 31.0327469171314
It is 1.52027668544987
It is 2.2485724867584
It is 10.6191589151146
It is 0.827340811845958
It is 0.365990752095503
It is 6.01584646652215

Date1999-08-23 19:41
FromMichael Coble
SubjectRe: A bit off topic->score generation
> Please forgive if this is not interesting.
> 
> The perl code below is a boiled down version
> of a program that wants to make a burst of notes
> which is dense at first, and then gets lighter.
> Much like the pattern that comes out of a spray
> paint can held at an angle to the surface.
> 
	Hello,

	This comes from perldoc "do a perldoc -f rand".  

    rand EXPR
    rand    Returns a random fractional number greater than or equal to
            `0' and less than the value of EXPR. (EXPR should be
            positive.) If EXPR is omitted, the value `1' is used.
            Automatically calls `srand....

It says that rand will either give a random number between 0 and
"EXPR" or between 0 and 1 if "EXPR" isn't there.  So the first example
is really more like: $it = (((100 * rand) * rand) * rand); and each
successive call is getting a random number between 0 and the result of
a call to rand.  The second is multiplying $it with a random number
between 0 and 1.

	hope this helps,

-*-*-*-*-*-*-*-*-*-*-*-*-*=*-*-*
Michael Coble: Director, Client Engineering, 24/7 Media Inc.
funstuff: http://www.panix.com/~coble/
-*-*-*-*-*-*-*-*-*-*-*-*-*=*-*-*

> #!/usr/bin/perl
> 
> for($x = 0; $x < 30; ++$x){
>         $it  = 100 * rand * rand * rand;
>         print "It is $it\n";
> }
> 
> print "XXXXXXXXXX\n";
> 
> for($x = 0; $x < 30; ++$x){
> 
>         $it = 100;
>         $it *= rand;
>         $it *= rand;
>         $it *= rand;
> 
>         print "It is $it\n";
> }
> 
> -------------------------------------------------------
> 
> It is 14.4036914221942
> It is 64.0403301455081
> It is 92.0018395874649
> It is 86.0313134733588
> It is 94.1714564803988
> It is 28.7829398643225
> It is 4.56200079061091
> It is 52.9926896095276
> It is 12.277115136385
> It is 65.0413279421628
> It is 7.03556826338172
> It is 58.5801591631025
> It is 43.5281078331172
> It is 64.0121327247471
> It is 58.7811752222478
> It is 24.898499250412
> It is 30.1713058259338
> It is 69.1552561242133
> It is 43.1361183989793
> It is 44.8441555257887
> It is 6.85915164649487
> It is 66.7636311613023
> It is 56.5284450538456
> It is 47.2567927092314
> It is 76.6749755479395
> It is 30.751428892836
> It is 75.7148835342377
> It is 22.4481104407459
> It is 45.5015169922262
> It is 30.3448522929102
> XXXXXXXXXX
> It is 0.76186388394069
> It is 21.3483627110067
> It is 34.4190002005938
> It is 0.130956948373957
> It is 0.239052579001631
> It is 1.3333306923856
> It is 16.7682933320958
> It is 33.6714633776643
> It is 25.1988224999129
> It is 56.3710418350352
> It is 0.614277701366594
> It is 34.1737601536983
> It is 0.581045287377612
> It is 19.6711942362409
> It is 4.92022134523882
> It is 2.09921444154036
> It is 3.04495186204821
> It is 2.59705455484509
> It is 37.7499712346738
> It is 17.5143909592512
> It is 14.5600427698617
> It is 34.2413973866594
> It is 31.0327469171314
> It is 1.52027668544987
> It is 2.2485724867584
> It is 10.6191589151146
> It is 0.827340811845958
> It is 0.365990752095503
> It is 6.01584646652215
> It is 32.4042397744241
>