Hi, James. Even if calling an external random function, don't you always have the problem of calling it with a different seed each time to get a different stream at each run?
If the external function uses, for example, time() to set a different seed, I feel that it would be easier to have a primitive that implements time() to be used with a deterministic (it couldn't be otherwise on a computer) seeded pseudo-random generator. I tested Faust's no.noise with arbitrary seeds and the uniformity seems to be preserved over time, i.e., the function still averages to 0 regardless of the seed. The fact that the stream may be more or less correlated regards the fact that LCGs are not so good for unpredictability, but still acceptable as noise generators for the music domain, I believe. As you suggest below and how I suggested in my previous email, I believe that the only way to get non-deterministic behaviours is to involve real-world phenomena such as sampling an ADC to seed a function. If we consider that some scenarios may not have an ADC, I think that a primitive implementing C++'s time() or similar could be best at the moment. Ciao, Dario On Thu, 6 May 2021 at 11:23, James Mckernon <jmcker...@gmail.com> wrote: > This is a bit of a limitation of faust for generative-type work. > > Faust's no.noise gives part of what one wants from randomness: the > values in its sequence are uncorrelated with each other. However, it > fails to give you the other thing one would want: it is deterministic, > i.e. it gives the same sequence between different runs. This isn't > really a problem when you are using noise at audio rate (it's all just > white noise), but using it for random control of parameters results in > something like the following: https://xkcd.com/221/ . > > A couple of approaches can be suggested. > > It is possible to write a c function returning a random integer and > call it from faust's FFI. Because faust considers all function calls > with the same parameters to be the same, if you want more than one > stream of randomness, you need to pass a dummy argument, which can be > ignored in the c function, but forces faust to differentiate the > different function calls and actually call the c function separately > for each of them. In other words, if you want three random variables, > your code should contain calls rnd(0), rnd(1), and rnd(2). If it > contains three calls of rnd(0) (or just to rnd()), you will get the > same random number back three times. > > You can call this foreign function whenever you need a new random > value, but when I was playing with this, I found it best to call out > to a foreign function only at the start to initialise ('seed') the > random stream, then iterate that stream within faust, with a function > similar to no.noise, but taking a seed argument. Unfortunately, I > can't remember why I ended up preferring this way.... > > I have some code for this approach which I can share if anyone is > interested. > > The foreign function approach works well, but only for compiling to c > targets; I believe that when compiling to llvm, foreign functions are > not available. (Perhaps someone could correct me if I'm wrong.) This > includes faustlive, and perhaps the faust IDE (does this use llvm? I > know it doesn't compile to c....) For these situations, I wrote a sort > of 'preprocessor' script, which takes faust code and does a simple > find-and-replace, replacing instances of a certain token with random > numbers. I then fed this script's output to faustlive. I guess the > same approach could be used for the IDE. I don't really want to share > the script I wrote for this, as it does a lot of other things, too, > and is quite personal to my requirements, and I'm not really willing > to do the work to clean it up to a shareable state. However, if anyone > wants to implement their own version of the idea (it's quite > straightforward), I can provide a couple of tips - let me know if > you're interested and I will mention them. > > Another approach could be to introduce some randomness from a human > source (like adding a button which can be clicked to start a process > at a random, unpredictable time). Or from an external input audio > channel. > > Finally, it's not really my place to propose this, but adding a new > primitive that gives random values would solve this problem. It would > be cool to have a way to get random values on all platforms, and it > seems like it wouldn't be unreasonably complex to add. But again, this > is a question for the developers of faust and isn't really my > business. > > Cheers, > James > > > On 5/6/21, riluan perfile <sc3...@gmail.com> wrote: > > I'm glad this question has been asked, > > was wondering myself how to do more generative work with Faust. > > > > Has anybody some more 'generative' examples to study ? > > > > Thanks > > > > On Thu, 6 May 2021 at 03:00, Julius Smith <julius.sm...@gmail.com> > wrote: > > > >> Hi Bob, > >> > >> You could use latch to sample the random number stream. However, it's > >> more efficient to do something that can be completed at compile time, > >> e.g., > >> > >> rtz = (*(1103515245) + 12345) & mask; > >> rt(i) = seq(j,i+1,rtz) / RANDMAX; > >> process = 1 <: par(i,N,*(rt(i))); > >> > >> > >> On Wed, May 5, 2021 at 5:19 PM Bob Bobsled <thebobbobs...@gmail.com> > >> wrote: > >> > >>> > >>> Hi, > >>> I've pondered this code for a while, and am failing to understand how > to > >>> declare a variable which has a single random value. Of course this > code > >>> creates random values at the sample rate. How would you get just one > >>> value > >>> instead of a constant stream of values? > >>> > >>> mynoise = random / RANDMAX > >>> with{ > >>> mask = 4294967295; // 2^32-1 > >>> random = +(12345) ~ *(1103515245) & mask; // "linear congruential" > >>> RANDMAX = 2147483647.0; // = 2^31-1 = MAX_SIGNED_INT in 32 bits > >>> }; > >>> process = mynoise; > >>> > >>> In other words, one would like to be able to do something such as this: > >>> process = os.osc(myrandomvalue); > >>> > >>> I understand there are various ways to provide frequencies, graphical > >>> and > >>> non-graphical. What I'm fundamentally searching for is how to declare a > >>> variable with a single random value. I cannot seem to figure out how > to > >>> slow down or stop things from flowing at the SR other than set SR to 1. > >>> > >>> Regards, > >>> Bob > >>> _______________________________________________ > >>> Faudiostream-users mailing list > >>> Faudiostream-users@lists.sourceforge.net > >>> https://lists.sourceforge.net/lists/listinfo/faudiostream-users > >>> > >> > >> > >> -- > >> "Anybody who knows all about nothing knows everything" -- Leonard > >> Susskind > >> _______________________________________________ > >> Faudiostream-users mailing list > >> Faudiostream-users@lists.sourceforge.net > >> https://lists.sourceforge.net/lists/listinfo/faudiostream-users > >> > > > > > _______________________________________________ > Faudiostream-users mailing list > Faudiostream-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/faudiostream-users >
_______________________________________________ Faudiostream-users mailing list Faudiostream-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/faudiostream-users