Logic for selecting terms w max_expansions and phrase_prefix query

Is there a certain logic as to how max_expansions works in a phrase_prefix search? If we run this search multiple times, we get a different number of results.

If I look at the query sent to Lucene, I can see that the expansions contain different sets of terms each time I run the query. Does this seem right? Are the expansion terms chosen randomly?

We're using the following query w phrase_prefix:

> {  
>    "query":{  
>       "bool":{  
>          "must":[  
>             {  
>                "bool":{  
>                   "should":[  
>                      {  
>                         "match":{  
>                            "field1":{  
>                               "query":"justin",
>                               "type":"phrase_prefix",
>                               "max_expansions":250
>                            }
>                         }
>                      },
>                      {  
>                         "terms":{  
>                            "field1":[  
>                               "justin"
>                            ]
>                         }
>                      }
>                   ],
>                   "minimum_should_match":"1"
>                }
>             },
>             {  
>                "bool":{  
>                   "should":[  
>                      {  
>                         "match":{  
>                            "field2":{  
>                               "query":"900",
>                               "type":"phrase_prefix",
>                               "max_expansions":250
>                            }
>                         }
>                      },
>                      {  
>                         "match":{  
>                            "field3":{  
>                               "query":"900",
>                               "type":"phrase_prefix",
>                               "max_expansions":250
>                            }
>                         }
>                      }
>                   ],
>                   "minimum_should_match":"1"
>                }
>             },
>             {  
>                "bool":{  
>                   "should":[  
>                      {  
>                         "match":{  
>                            "field4":{  
>                               "query":"whirlpool",
>                               "type":"phrase_prefix",
>                               "max_expansions":250
>                            }
>                         }
>                      },
>                      {  
>                         "terms":{  
>                            "field5":[  
>                               "12012096",
>                               "12319482",
>                               "12243232",
>                               "12297888"
>                            ]
>                         }
>                      }
>                   ],
>                   "minimum_should_match":"1"
>                }
>             }
>          ],
>          "filter":{  
>             "term":{  
>                "field6":"F"
>             }
>          }
>       }
>    }
> }