Re: [chuck-users] Non-random random number
'Noise' object does not interfere. 'SubNoise' does. david
All of those instruments contain noise. Likely a Noise object. Wonder if Noise itself does a seed? I'll check.
Sent from my iPhone
On Oct 9, 2013, at 4:40 PM, David Code
wrote: Apparently, the non-random bug does not happen after declaration of all STK instruments, just some of them: BlowBotl, BlowHole, Clarinet, Flute, Saxofony, StifKarp, VoicForm
And the problem occurs with both Std.rand2 and Std.rand2f (I haven't conducted any more tests yet to see under what other conditions it might happen.)
david
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 code at wmich.edu
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
From: David Code
Subject: Re: [chuck-users] Non-random random number Date: October 9, 2013 6:37:13 PM EDT To: chuck-users@lists.cs.princeton.edu Reply-To: ChucK Users Mailing List Upon a quick check it appears that Math.random is fine. I guess I just need to retro-fit my older ChucK files.
david
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: (504) 865-2606 Voice & Text: (504) 315-5167 jvalbert at loyno.edu http://www.loyno.edu/~jvalbert
On Oct 9, 2013, at 4:40 PM, David Code
wrote: Apparently, the non-random bug does not happen after declaration of all STK instruments, just some of them: BlowBotl, BlowHole, Clarinet, Flute, Saxofony, StifKarp, VoicForm
And the problem occurs with both Std.rand2 and Std.rand2f (I haven't conducted any more tests yet to see under what other conditions it might happen.)
david
On Oct 9, 2013, at 5:40 PM, David Code wrote:
Apparently, the non-random bug does not happen after declaration of all STK instruments, just some of them: BlowBotl, BlowHole, Clarinet, Flute, Saxofony, StifKarp, VoicForm
And the problem occurs with both Std.rand2 and Std.rand2f (I haven't conducted any more tests yet to see under what other conditions it might happen.)
david
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 code at wmich.edu
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
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.
ChucK could probably do a better job working around those limitations, but
new code should definitely use Math.random() and related functions.
spencer
On Wed, Oct 9, 2013 at 4:37 PM, David Loberg Code
'Noise' object does not interfere. 'SubNoise' does.
david
All of those instruments contain noise. Likely a Noise object. Wonder if Noise itself does a seed? I'll check.
Sent from my iPhone
On Oct 9, 2013, at 4:40 PM, David Code
wrote: Apparently, the non-random bug does not happen after declaration of all STK instruments, just some of them: BlowBotl, BlowHole, Clarinet, Flute, Saxofony, StifKarp, VoicForm
And the problem occurs with both Std.rand2 and Std.rand2f (I haven't conducted any more tests yet to see under what other conditions it might happen.)
david
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-5434code at wmich.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
*From: *David Code
*Subject: **Re: [chuck-users] Non-random random number* *Date: *October 9, 2013 6:37:13 PM EDT *To: *chuck-users@lists.cs.princeton.edu *Reply-To: *ChucK Users Mailing List Upon a quick check it appears that Math.random is fine. I guess I just need to retro-fit my older ChucK files.
david
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: (504) 865-2606 Voice & Text: (504) 315-5167jvalbert at loyno.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-usershttp://www.loyno.edu/~jvalbert
On Oct 9, 2013, at 4:40 PM, David Code
https://lists.cs.princeton.edu/mailman/listinfo/chuck-users> wrote: * Apparently, the non-random bug does not happen after declaration of all STK instruments, just some of them:*>* BlowBotl, BlowHole, Clarinet, Flute, Saxofony, StifKarp, VoicForm*>* *>* And the problem occurs with both Std.rand2 and Std.rand2f*>* (I haven't conducted any more tests yet to see under what other conditions it might happen.)*>* *>* *>* david*>* *
On Oct 9, 2013, at 5:40 PM, David Code wrote:
Apparently, the non-random bug does not happen after declaration of all STK instruments, just some of them: BlowBotl, BlowHole, Clarinet, Flute, Saxofony, StifKarp, VoicForm
And the problem occurs with both Std.rand2 and Std.rand2f (I haven't conducted any more tests yet to see under what other conditions it might happen.)
david
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-5434code at wmich.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
On Wed, Oct 09, 2013 at 05:45:33PM -0700, Spencer Salazar wrote:
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.* ChucK could probably do a better job working around those limitations, but new code should definitely use Math.random() and related functions.*
Sorry I have been a bit absent. I'd like to remind the list that we have some interesting properties to our noise instruments. As they all share the same random function you can reset the random seed periodically and thus turn noise into noisy and pitched wave-tables. I still find that a interesting option (I wrote some one-liners based on this back then). There are two more or less conflicting concerns here; to what degree pieces can be reproduced has traditionally (in CSound and so on) been a concern for systems like ours. "fixing" "issues" like this may break pieces, in theory that might make compositions become unplayable. This is no concern for me, but more serious composers might care. The current system has one huge issue in that using that technique on the sound level makes real random melodies impossible on the score level, unless we write our own RNG. That last option is not particularly hard as examples are available, even accessible ones aimed at our kind of usage (see John Ffitch's article in the CSound Handbook), but it does look a bit strange and -frankly- limited. I'd propose a "seed" function for every instrument instance that uses noise as well as keeping the one for global Math functions. That would keep all options open at the cost of a very small memory increase per such UGen and breaking some compositions. I don't care about preserving those one-liners as those were deliberately perverse anyway. I also rate the chances of serious composers writing to this kind of "bug" specifically in ChucK as rather low, but I might be mistaken. Yours, Kas.
participants (3)
-
David Loberg Code
-
Kassen
-
Spencer Salazar