adieyal / comfyui-dynamicprompts

ComfyUI custom nodes for Dynamic Prompts
MIT License
187 stars 20 forks source link

Random doesn't seem to be random... #48

Open CHollman82 opened 3 weeks ago

CHollman82 commented 3 weeks ago

I'm using 2 different "Random Prompt" nodes and each one merely references a single wildcard file. The wildcard file used by the first Random Prompt node has 4 lines and the second one has 6 lines.

I've logged the line index chosen from each of the 2 wildcard files for each seed from 1 to 20 and here are the results:

seed - index1/index2 1 - 1/1 2 - 0/6 3 - 1/1 4 - 1/1 5 - 4/4 6 - 4/6 7 - 2/2 8 - 1/1 9 - 3/3 10 - 4/4 11 - 3/3 12 - 3/3 13 - 2/2 14 - 0/0 15 - 1/1 16 - 2/2 17 - 4/4 18 - 1/1 19 - 0/5 20 - 1/5

So it is clear that if the second number is 4 or less then the first number will match. This makes sense because the first wildcard file only has 4 lines, so if it chooses a number larger than 4 something else happens (I'm a software engineer, I would expect a simple modulus/wrap operation here but that's clearly not it either).

You're not re-seeding your RNG between successive generations which means multiple uses will result in the same line index every time and that's not ideal. What I don't understand is why don't you just generate a large random number (say from 2^31 to 2^32) and then use modulus to pick the line number in the wildcard file? That way as long as the wildcard files have a different number of lines you'll always get different results.

BUT WAIT... when I generate seed 0 I get 1/4... which doesn't follow the above pattern because 4/4 would be valid and expected.

More troubling still is the fact that successive generations of seed 0 give DIFFERENT RESULTS! This behavior appears to be UNIQUE to seed 0... every other seed value I've tried gives identical repeat results.

Finally... if I use much larger seeds, like 6 or 7 digit seeds, I get entirely different results... here is a collection of results using "random" seeds, all of which were very large numbers, sorted (not in chronological order): 0/0 0/2 0/3 0/6 1/0 2/2 2/4 2/4 2/4 2/4 2/4 2/6 3/3 3/5 3/5 3/5 3/5 3/5 3/5 4/1 4/1 4/1 4/3 4/4 4/6 4/6

Now... what in the ever-loving f*** is going on here? In 25 results I only got a SINGLE line 1 result for the first wildcard file... a file that only has 4 lines. On top of that there are CLEARLY combinations that are strongly favored, such as 2/4 and 3/5...

I've never written software in python but I have 17 years of experience writing C++ and this behavior is downright confusing. You might say I don't have enough data to support any kind of conclusion (I understand that "randomness" can look not random and I know of the anecdote of old CD/MP3 players making their "shuffle" mode less random to make it appear more random) but I have THOUSANDS of actual image generations and I noticed this pattern in all of them, where certain wildcard file 1 selections were strongly correlated with wildcard file 2 selections.

I'm not being picky here... this behavior completely ruins what I'm trying to do. Is it possible to either re-seed the RNG each time you use it or to simply pick a very large random value and then index the wildcard file with that value modulus the number of lines in the file?