How is iPhone music shuffled?

X songs, when shuffled, is it randomly shuffled or based on listening history, or something other than random?

Its a random list, when the list is fully played/skipped, it will regenerate another list, which is why you occasionally get the same song back to back, the end of one list and the start of the next having the same song.

can you help me out?