You need to be careful with what you call "random". I'll give you an example: I wrote a similar routine rnd() to get a 0/1 bit from the thousands' digit of time.time(). (I may have a bug, so this is why I ask you to replicate the result.) Indeed, the bit turns out 0 or 1, 50% of the time. So far so good. But their correlation is atrocious: 0 is followed by 0 much more often than by 1, and vice versa. Try a piece of code like this: (these comments won't respect the whitespace indent, so please use your imagination; I am using a vertical bar to separate lines.) def corr(): | histo = [[0, 0], [0, 0]] | value = rnd() | for n in range(1000000): | prev, value = value, rnd() | histo[prev][value] += 1 | # now, outside of the for loop | return histo A typical returned value is [[499336, 207], [207, 500250]], far from the [[250000, 250000], [250000, 250000]] I would have expected. Try it with your own bit generator and tell me what you get. And please feel free to prove me wrong if I made a major mistake, which is very possible. Thanks!
@NikolajKuntner
3 ай бұрын
I sample with manual keyboard strokes - if you sample it in a for-loop in quick succession, the idea might break. I haven't tested/proofread your code yet, but it's a good remark in general. I didn't actually look at either the time implementation or practical tests.
Пікірлер: 4