Hi Kirill,
the default behavior is as follows:
STAR outputs the multiple alignments in a "quasi-random" order, that depends on the sorting of suffix array indexes. This order is fully reproducible from run to run provided you use the same genome indexes.
However, it's not truly random, so selecting only one of the alignments will introduce significant biases in the genome coverage.
The primary alignment is selected as the first alignment with the top score, so it's not guaranteed to be the first (HI:i:1) alignment.
Since 2.5.0b, I have introduced --outMultimapperOrder Random option to output multiple alignments in random order, and --outSAMmultNmax parameter to limit the number of output alignments for multimappers.
If you use either of these parameters, first of all the top scoring alignments are brought to the top of the output list, i.e. they will have HI:i:1,2...
Next, if you use --outMultimapperOrder Random the top scoring alignments will be shuffled, and separately all the other (poorer) alignments will be shuffled, so their order is truly random.
Next, the very first alignment (i.e. HI:i:1) will be primary, and all others marked as secondary.
Finally, only --outSAMmultNmax alignments from this list will be output.
If you use --outMultimapperOrder Random --outSAMmultNmax 1, you will get only one alignment in the output, randomly chosen from the top scoring alignments. This is the behavior most commonly sought after.
Parameter --runRNGseed can be used to set the random generator seed. However, even with the same seed, the ordering of multi-mapping alignments of each read, and the choice of the primary alignment will vary from run to run, unless only one thread is used.
Hope this makes it clearer, please let me know if you have further questions.
Cheers
Alex