Here is my attempt:
It works okay (at least there is some variation), but I think the problem is that there is an average time for [loadbang] so the probability for some numbers is higher then for others.
Best way to create random seed on [loadbang] with vanilla?
Here is my attempt:
It works okay (at least there is some variation), but I think the problem is that there is an average time for [loadbang] so the probability for some numbers is higher then for others.
@whale-av I agree with your point. We try to usually solve different problems in a logical fashion but the nature is the way it is and it doesn't give a damn about what we think about it's way of doing things. I strongly believe that understanding this entropy could lead to a better understanding of nature. Up to now there are to many definitions of entropy and we still don't have a deep understanding of it. I apologize for the math i still think i need to simplify it to be more friendly.
@Boran-Robert living nature is really at the complete opposite end of the scale of entropy as we are talking about it....... high.... or low...... I can't remember.
Of course earthquakes are not living.
Living things, their structures and patterns are at the same end of the scale as your funny squiggles.
Anyway, time for bed.
David.
@whale-av Yes. The fundamental output of the brain is motion. Consciousness is just the feedback loop that colours the motion.
@whale-av i tried the mic approach. Actually I do not need a mic connected, but a sound device. Here is an attempt with Ofelia (yes, not vanilla), it generates the seed from microseconds, so at least 1000000 possibilities a second (if there are that many different seeds)
and interestingly seed seems to accept double precision floats?
Btw: It seems that only since 2016 computers can generate "real" random numbers:
https://futurism.com/scientists-enable-computers-to-generate-true-random-numbers
The result sounds quite simple and very similar to what we are trying here:
"The randomness extractor harvests randomness from two sources in the environment, such as input from the mouse or the keyboard, converting their coordinates into a string of numbers, and weeding out the predictable rubbish to end up with a true random number."
Here is the according paper: https://eccc.weizmann.ac.il//report/2015/119/
But it is too complicated for me, and I am satisfied with the (pseudo) random possibilities from Pure Data.
Another possibility to gather entropy could be to use [netsend] to send some data though the local machine. Maybe this is not different than doing some calculations. It comes with a message about the connection. If the port is already in use, it might not work. Other than that, it looks like a possible way to go.
In the example i use the result as a seed for a [random] to spread the outcome over the complete range. This should then be used as the seed for the actual [random]: netseed.pd
In addition, the bang to reset could be removed to maybe even get a little bit more entropy from the load time.
I don't know if this does anything with sending anything, but it has no message and should work even when the port is already in use: netseed2.pd
@Jona I haven't tested it yet, but if [array random] works like [random], it should always produce the same quantile after a restart and thus always select a certain value from the randomly produced list, so i am not sure if there is any more entropy as just one [realtime] would produce...
@ingox
that would be true, but i am not sure.
thats about array random:
"array random" makes a pseudo-random number from 0 to 1 and outputs its quantile (which will therefore have probabilities proportional to the table's values.)
thats about array quantile:
"array quantile" outputs the specified quantile of the array - so for instance, the 0.5 quantile is the median of the array. This generalizes the "array random" function allowing you to use the same source of randomness on several arrays, for example. Negative numbers in the array are silently replaced by zero. Quantiles outside the range 0-1 output the x values at the two extremes of the array (0 and 99 here).
So if i understand it right, the random array number depends on all array values (the median of the array). and not simply returns one of the array elements randomly?
I addition set the seed of [array random] with [array sum].
Here is a variation: randomseed_array_3.pd perhaps much too complicated anyway, i think for my needs there is enough variation in those examples.
@Jona Yes, to set the seed that way would really take all the values into account.
Still, with such a kind of operations, it is the question, if it really adds to the entropy. For example, if you roll a dice, you get one out of six numbers equally distributed. If you roll one thousand dices and add up the results, you get numbers from 1000 to 6000, but they are not equally distributed any more.
Another example would be having a true random number between 0 and 1. If you take 1.000 numbers and take the average, it would probably be around 0.5. If you take 10.000 numbers instead, you probably get even closer to 0.5, so the entropy is actually decreased. Whether the entropy increases by taking the sum, i am not sure. But there is some randomness for sure.
Without the random seed i am pretty sure that the other numbers would not increase the entropy, as once the list is generated, the result is determined and it would not change the entropy if you instead choose another number than the selected quantile, for example the next number or the opposite number. But this is just me guessing.
Or to put it in other words: At the end of the process, you will have one number between 0 and 1 that is the result of one [realtime] operation. If it is this number or another may not make a difference.
@ingox I added some complexity with [cos], now there are a lot more different values in the array.
the "problem" that I tried to avoid is that [until] needs an average time, and that average time should not produce an average seed...
@Jona I don't understand why this randomyness2.pd does not produce the same seed list every time the patch is opened.
The idea is to save a seed for the next opening of the patch....... a number saved that depends on the length of time the patch was open for....... which should be random.
I expected the seed values captured every 5 seconds would always be the same but they are not.
I can only deduce that it has something to do with other cpu activity at loadbang.
David.
@whale-av isnt it because the output of [realtime] is different everytime? Even if you reset realtime before, the return value can be slightly different, but then there is an average value...
@Jona It seems to be elapsed time for the patch (unless you reset)....... not Pd, and not uptime.
And as it is unreliable because?...... should be sufficient to derive a random seed if you just take the last 3 decimals at loadbang......... i.e. 399 from a value of 0.577399
In fact that takes me back to your op....... where you take that [realtime] variation, but as you say there will not be an even distribution.
But in the trailing decimals there should be.
I am not sure how you strip them out though.
You could use expected value [-] value followed by [*] but we need to know whether the values are similar on every computer in that case.
David.
@whale-av You can do something like
[* 10000]
|
[div 1000]
@ingox Distribution test required......... but not nice on an ssd........ randomyness4.pd
David.
@whale-av Yes, it should be [mod] of course... Sorry, was in a hurry
Don't know how to make a distribution test on that. I run a test 10.000 times, but i would not open and close a patch that many times. I think in principle it should be ok. But then again, some calculation can be done in addition, just to add some time in case the ssd is too fast...
@ingox No problem.
Just did a short test and it's no good I think....... much repetition.
So, i created this abstraction [random2], that is a pseudo-random number generator just like [random], but unlike [random] it does not repeat itself after the restart of Pd. It works like my examples above, but it reads its own code into a [text], changes the seed inside the text and writes the text back to its own location, overwriting itself. This way it doesn't need another file to store the seed or send any messages to the console. It works silently.
Each time it gets loaded, it will use another seed and produce another chain of pseudo-random numbers.
It works on linux, even when the abstraction is within a sub-directory. I wonder if it also works on Windows and OS X. It should produce different numbers after each start of Pd and it should only overwrite the abstraction within the folder "random2" (The creation time of the abstraction would change in the OS file explorer.).
This is the abstraction together with a test patch: random2-test.zip (updated)
@ingox it works on windows. interesting way to save something without "saving"...
i still tried to find a simpler solution without saving, this is the result, not perfect but good enough to work with: randomseed_simple.pd
Oops! Looks like something went wrong!