<div dir="ltr"><div>Thanks for letting us know about this. After some investigation, it looks like a bug in the underlying C functions rand()/srand(), which are widely regarded to be pretty bad like this. Each of those STK ugens re-seeds rand() with the current time in seconds, via srand(), when the ugen is created. Evidently the first value out of rand() after this reseeding is not very random at all, and would explain what is happening here. </div>
<div><br></div><div>ChucK could probably do a better job working around those limitations, but new code should definitely use Math.random() and related functions. </div><div><br></div><div>spencer</div><div class="gmail_extra">
<div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 9, 2013 at 4:37 PM, David Loberg Code <span dir="ltr"><<a href="mailto:d.loberg.code@wmich.edu" target="_blank">d.loberg.code@wmich.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div>'Noise' object does not interfere.</div>
<div>'SubNoise'  does.</div><div><br></div><div>david</div><div><br></div><div><br><blockquote type="cite"><font color="#000000"><pre style="line-height:normal;text-indent:0px;letter-spacing:normal;text-align:start;font-variant:normal;text-transform:none;font-style:normal;white-space:pre-wrap;font-weight:normal;word-spacing:0px">
All of those instruments contain noise.  Likely a Noise object.  Wonder if Noise itself does a seed?  I'll check.

Sent from my iPhone</pre><div><br></div></font><br></blockquote><div><br></div><blockquote type="cite"><div style="word-wrap:break-word"><div><div>

</div>
<br><div><div><div class="h5"><div>On Oct 9, 2013, at 4:40 PM, David Code <<a href="mailto:d.loberg.code@wmich.edu" target="_blank">d.loberg.code@wmich.edu</a>> wrote:</div><br></div></div><blockquote type="cite"><div>
<div class="h5"><div style="word-wrap:break-word"><div>Apparently, the non-random bug does not happen after declaration of all STK instruments, just some of them:</div><div><span style="font-family:Monaco;font-size:13px">BlowBotl, BlowHole, Clarinet, Flute, Saxofony, StifKarp, VoicForm</span></div>
<div><span style="font-family:Monaco;font-size:13px"><br></span></div><div><span style="font-family:Monaco;font-size:13px">And the problem occurs with both Std.rand2 and Std.rand2f</span></div><div><span style="font-family:Monaco;font-size:13px">(I haven't conducted any more tests yet to see under what other conditions it might happen.)</span></div>
<div><span style="font-family:Monaco;font-size:13px"><br></span></div><div><span style="font-family:Monaco;font-size:13px"><br></span></div><div><span style="font-family:Monaco;font-size:13px">david</span></div><div><br></div>
<div><br></div><div><blockquote type="cite"><pre style="white-space:pre-wrap;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;word-spacing:0px">
Forgive me if this was already discussed on the list before.  I am puzzled about a non-random random number.
When the random number is calculated right after an STK instrument is declared, the result is not random.  It is the same number every time.
However, if the same code occurs without an STK declaration before it, the result is random.


while (true)
{
StifKarp stu => dac;
int randy;
Std.rand2(0,10) => randy;
<<<"here are three random numbers",
Std.rand2(0,10), Std.rand2(0,10),Std.rand2(0,10),
"and NON-random Randy", randy >>>;

Std.rand2(0,10) => randy;
<<<"here are three more random numbers",
Std.rand2(0,10), Std.rand2(0,10),Std.rand2(0,10),
"and random Randy", randy >>>;
1000::ms => now;
}


david

David Loberg Code
School of Music
Western Michigan University
1903 W Michigan Ave
Kalamazoo, MI 49008-5434
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">code at wmich.edu</a>
</pre></blockquote></div><div><br></div></div></div></div><div class="im">_______________________________________________<br>chuck-users mailing list<br><a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br></div></blockquote></div><br></div></div><br><br><br><br><br><br><br>
<div style="margin:0px"><span style="font-family:Helvetica;font-size:medium;color:rgb(127,127,127)"><b>From: </b></span><span style="font-family:Helvetica;font-size:medium">David Code <<a href="mailto:d.loberg.code@wmich.edu" target="_blank">d.loberg.code@wmich.edu</a>><br>
</span></div><div style="margin:0px"><span style="font-family:Helvetica;font-size:medium;color:rgb(127,127,127)"><b>Subject: </b></span><span style="font-family:Helvetica;font-size:medium"><b>Re: [chuck-users] Non-random random number</b><br>
</span></div><div style="margin:0px"><span style="font-family:Helvetica;font-size:medium;color:rgb(127,127,127)"><b>Date: </b></span><span style="font-family:Helvetica;font-size:medium">October 9, 2013 6:37:13 PM EDT<br></span></div>
<div style="margin:0px"><span style="font-family:Helvetica;font-size:medium;color:rgb(127,127,127)"><b>To: </b></span><span style="font-family:Helvetica;font-size:medium"><a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>
</span></div><div style="margin:0px"><span style="font-family:Helvetica;font-size:medium;color:rgb(127,127,127)"><b>Reply-To: </b></span><span style="font-family:Helvetica;font-size:medium">ChucK Users Mailing List <<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a>><br>
</span></div><div><div class="h5"><br><br><div style="word-wrap:break-word"><div>Upon a quick check it appears that Math.random is fine.  </div><div>I guess I just need to retro-fit my older ChucK files.</div><div><br></div>
<div>david</div><div><br></div><div><blockquote type="cite"><pre style="line-height:normal;text-indent:0px;letter-spacing:normal;text-align:start;font-variant:normal;text-transform:none;font-style:normal;white-space:pre-wrap;font-weight:normal;word-spacing:0px">
Does it do it with Math.random too?

-Jeff


--
Jeffrey Albert, Ph.D.
Assistant Professor of Music Industry Technology
Loyola University New Orleans
College of Music and Fine Arts
6363 St. Charles Ave.
Campus Box 8
New Orleans, LA 70118

Office: Communications/Music Complex 428P
Office Phone: <a href="tel:%28504%29%20865-2606" value="+15048652606" target="_blank">(504) 865-2606</a>
Voice & Text: <a href="tel:%28504%29%20315-5167" value="+15043155167" target="_blank">(504) 315-5167</a>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">jvalbert at loyno.edu</a>
<a href="http://www.loyno.edu/~jvalbert" target="_blank">http://www.loyno.edu/~jvalbert</a>


On Oct 9, 2013, at 4:40 PM, David Code <<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">d.loberg.code at wmich.edu</a>> wrote:

><i> Apparently, the non-random bug does not happen after declaration of all STK instruments, just some of them:
</i>><i> BlowBotl, BlowHole, Clarinet, Flute, Saxofony, StifKarp, VoicForm
</i>><i> 
</i>><i> And the problem occurs with both Std.rand2 and Std.rand2f
</i>><i> (I haven't conducted any more tests yet to see under what other conditions it might happen.)
</i>><i> 
</i>><i> 
</i>><i> david
</i>><i> </i></pre></blockquote><div><br></div></div><br><div><div>On Oct 9, 2013, at 5:40 PM, David Code wrote:</div><br><blockquote type="cite"><div style="word-wrap:break-word"><div>Apparently, the non-random bug does not happen after declaration of all STK instruments, just some of them:</div>
<div><span style="font-family:Monaco;font-size:13px">BlowBotl, BlowHole, Clarinet, Flute, Saxofony, StifKarp, VoicForm</span></div><div><span style="font-family:Monaco;font-size:13px"><br></span></div><div><span style="font-family:Monaco;font-size:13px">And the problem occurs with both Std.rand2 and Std.rand2f</span></div>
<div><span style="font-family:Monaco;font-size:13px">(I haven't conducted any more tests yet to see under what other conditions it might happen.)</span></div><div><span style="font-family:Monaco;font-size:13px"><br></span></div>
<div><span style="font-family:Monaco;font-size:13px"><br></span></div><div><span style="font-family:Monaco;font-size:13px">david</span></div><div><br></div><div><br></div><div><blockquote type="cite"><pre style="line-height:normal;text-indent:0px;letter-spacing:normal;text-align:start;font-variant:normal;text-transform:none;font-style:normal;white-space:pre-wrap;font-weight:normal;word-spacing:0px">
Forgive me if this was already discussed on the list before.  I am puzzled about a non-random random number.
When the random number is calculated right after an STK instrument is declared, the result is not random.  It is the same number every time.
However, if the same code occurs without an STK declaration before it, the result is random.


while (true)
{
StifKarp stu => dac;
int randy;
Std.rand2(0,10) => randy;
<<<"here are three random numbers",
Std.rand2(0,10), Std.rand2(0,10),Std.rand2(0,10),
"and NON-random Randy", randy >>>;

Std.rand2(0,10) => randy;
<<<"here are three more random numbers",
Std.rand2(0,10), Std.rand2(0,10),Std.rand2(0,10),
"and random Randy", randy >>>;
1000::ms => now;
}


david

David Loberg Code
School of Music
Western Michigan University
1903 W Michigan Ave
Kalamazoo, MI 49008-5434
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">code at wmich.edu</a>
</pre></blockquote></div><div><br></div></div></blockquote></div><br></div><br><br><br><br></div></div><div class="im">_______________________________________________<br>chuck-users mailing list<br><a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br></div></blockquote></div><br></div><br>_______________________________________________<br>

chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
<br></blockquote></div><br></div></div>