Random Generator

The Random Generator, also popularly known as 7-bag, is the algorithm used to generate the sequence of tetrominoes in Tetris-branded games that follow the Tetris Guideline. Despite its generic appearance, presumed employees of BPS are known to treat the term "Random Generator" as a unique name which refers only to this particular algorithm.
The Random Generator generates a sequence of all seven tetrominoes (I, J, L, O, S, T, Z) in a random order, as if the pieces were drawn from a bag. The resulting sequence of seven tetrominoes is added to the queue, and another bag is then generated. There are 7!, or 5,040, permutations of seven elements, and it is believed that Tetris assigns a nearly equal probability to each of these. The result is that "droughts", in which a particular piece does not appear for an extended period, are limited in severity and less likely to occur than if all pieces were equally likely to be the next piece at all times. The Random Generator can produce a run of no more than 12 tetrominoes between one I piece and the next, and runs of S and Z tetrominoes are limited to a length of 4. (As an exception, in the Tetris The Grand Master Ace implementation of the Random Generator, the first piece of the first bag is always I, J, L, or T, just as in the traditional TGM randomizer.)
While the number of tetrominoes in a single Random Generator bag is canonically 7, some games use bag algorithms with other bag sizes. The public beta of Tetris Online (Japan), for example, used an 8-bag randomizer. Additionally, not all Guideline-compliant games use the Random Generator in all modes. Tetris Worlds and Tetris Green, for instance, use a different randomizer in their Square modes, and TGM3 uses its own 35-bag variant of the TGM randomizer even under World Rule.
The Random Generator was originally developed for The New Tetris. This early version of the algorithm used a bag size of 63—nine of each piece—to allow for streaks to assist in square building, and to ensure players need not wait too long to receive pieces needed to complete squares.
"Snake" sequences
There are two "snake" tetrominoes, S and Z. As only two snakes will be in a given bag, a sequence of more than two snakes necessarily crosses the "seam" between bags. The probability of the next two bags having a sequence of four consecutive snakes, the maximum possible, is 1/(7*6*7*6) for each of SZSZ, SZZS, ZSSZ, and ZSZS, for a total of 1/441. Meanwhile, the probability of these being the three next pieces in the queue are 1/441 times the probability of being at position 6 in a bag, and so the probability of the next four pieces being SZSZ is 1/3087.
Let "AB|C" represent the final two pieces of one bag and the first piece of the next bag, and similarly, let "A|BC" represent the final piece of one bag and the first two of the next bag. The probability of any given AB|C (e.g., SZ|Z) is 1/(7*6*7) = 1/294.
There are four unique AB|C combos containing only snakes (SZ|Z, SZ|S, ZS|Z, and ZS|S), so the probability of getting a three-snake AB|C in two consecutive bags is 4/294. However, because such a sequence can only occur starting at the sixth position (out of seven) in a bag, the probability of such a sequence constituting the next three pieces at any point in the game is equal to 4/(294*7) = 2/1029. By symmetry, the A|BC probabilities are the same, and so for the Random Generator, the overall probability of any three consecutive pieces being snakes is 1/257.