Let's first write out the assumptions of a T-test.
- The distribution of the mean of the sample being tested is normal.
- The variance of this distribution is unknown.
- The sample is random.
In the common situation where you sample a bunch of people and want to make inference on the mean of a characteristic of the population such as height, weight, income etc... a random sample implies that you are using a non-deterministic method to select a sample from the population. In simple cases, addressed in most text books, you are looking at taking what is known as a "simple random sample"; a sample where each element of the population has equal probability of inclusion in a sample.
In a more general case, this sample need not be a simple random sample. The only requirement is that there is a non-deterministic method of generating the sample. However, it is important to note that the mean you are using as your test statistic is the population mean under this sampling method. In statistical theory this can be seen by taking random samples from non-uniform distributions, and in statistical practice this can be seen as non-uniform sampling from a finite population to adjust for peculiarities in the elements being sampled.