Bobulous wrote:Maybe stick with the database option if you really want a totally reliable zero-one-zero-one-zero-one sequence.
I suspect that artificially imposing a strict pattern may bias the results (with some viewers getting disproportionately more of one than the other).
If the poster really want to ensure that there is an exact 50/50 split (as if a couple one way or the other is going to have a bigger effect on the results than variations in the sample), then you should pregenerate a random sequence of bits that has exactly the right numbers of 0s and 1s that you're after (put them all in an array, and then shuffle, say), save it to a file, and then read from that. If you save them as '0' and '1' characters you can use fseek() and filesize() to find the last character in the file, fread() it, and then ftruncate().
You still have all the hassles of file-locking to contend with, and the same approach could be done with a database, but it would be less likely to contaminate your results with unwanted patterns that a zero-one-zero-one pattern might produce.
More hassle than it seems worth bothering about, in my opinion, though. If you're going to do anything statistical, it helps to know a bit about the odds. A sense of proportion helps 🙂
Pregenerated tables of random numbers ... that takes me back. In my day we didn't have random number generators we could just use. Even effective pseudorandom number generators were beyond our means. We had to get our random numbers generated in factories, where they'd be printed into books and published, and we'd read our numbers from out of those books (I think I might still have one around here somewhere).
Kids these days don't know how easy they have it....