Browse Source

Fix: bad math in shuffle failed to preserve server order for head of list

Rod Hynes 10 years ago
parent
commit
4cf4f50a8f
1 changed files with 2 additions and 2 deletions
  1. 2 2
      psiphon/dataStore_alt.go

+ 2 - 2
psiphon/dataStore_alt.go

@@ -389,7 +389,7 @@ func (iterator *ServerEntryIterator) Reset() error {
 	//     transaction is open.
 	//     (https://github.com/boltdb/bolt)
 	//
-	// So the uderlying serverEntriesBucket could change after the serverEntryIds
+	// So the underlying serverEntriesBucket could change after the serverEntryIds
 	// list is built.
 
 	var serverEntryIds []string
@@ -422,7 +422,7 @@ func (iterator *ServerEntryIterator) Reset() error {
 	}
 
 	for i := len(serverEntryIds) - 1; i > iterator.shuffleHeadLength-1; i-- {
-		j := rand.Intn(i)
+		j := rand.Intn(i+1-iterator.shuffleHeadLength) + iterator.shuffleHeadLength
 		serverEntryIds[i], serverEntryIds[j] = serverEntryIds[j], serverEntryIds[i]
 	}