I have a set $A$ of strings, and I have to sample (namely extract from it) uniformly (i.e. each string must have the same probability of extraction). But the strings haven't the same length, thus a random sample doesn't provide a uniform sample. Then, the paper that I'm reading tell me: you have to detect the differents possible lengths in the set that I call $n$.Define the distribution $\pi$ on $\{1,....,n\}$ by${\pi}_k = $ num strings of length k $/ |A|$Later, sampling a $k \in \{1,....,n\}$ according to $\pi$ , and later make a random extraction of a string from all the strings of length $k$ .But what mean sampling a $k \in \{1,....,n\}$ according to $\pi$? I imagine extract a k from $\{1,....,n\}$ whit  weighted probability according  to $\pi$ . But in this way it doesn't seem me to realize a uniform sampling.  This way of proceeding leaves me in doubt. Can someone confirm that it is right?(Actually I have not strings but DFA and I have not the set A but I can build it. I used strings and knowledge of $A$ for make simpler the explanation)
Uniformly sampling of a set of strings
regular languages;randomized algorithms;statistics;sampling