func ShuffleValidators(toShuffle []uint32, seed chainhash.Hash) []uint32 {
	shuffled := toShuffle[:]
	numValues := len(toShuffle)

	randBytes := 3
	randMax := uint32(math.Pow(2, float64(randBytes*8)) - 1)

	source := seed
	index := 0
	for index < numValues-1 {
		source = chainhash.HashH(source[:])
		for position := 0; position < (32 - (32 % randBytes)); position += randBytes {
			remaining := uint32(numValues - index)
			if remaining == 1 {
				break
			}

			sampleFromSource := binary.BigEndian.Uint32(append([]byte{'\x00'}, source[position:position+randBytes]...))

			sampleMax := randMax - randMax%remaining

			if sampleFromSource < sampleMax {
				replacementPos := (sampleFromSource % remaining) + uint32(index)
				shuffled[index], shuffled[replacementPos] = shuffled[replacementPos], shuffled[index]
				index++
			}
		}
	}
	return shuffled
}
// ShuffleValidators shuffles an array of ints given a seed.
ShuffleValidators shuffles an array of ints given a seed.
// ShuffleValidators shuffles an array of ints given a seed .
func ShuffleValidators(toShuffle []uint32, seed chainhash.Hash) []uint32 {
	shuffled := toShuffle[:]
	numValues := len(toShuffle)
	randBytes := 3
	randMax := uint32(math.Pow(2, float64(randBytes*8)) - 1)
	source := seed
	index := 0
	for index < numValues-1 {
		source = chainhash.HashH(source[:])
		for position := 0; position < (32 - (32 % randBytes)); position += randBytes {
			remaining := uint32(numValues - index)
			if remaining == 1 {
				break
			}
			sampleFromSource := binary.BigEndian.Uint32(append([]byte{'\x00'}, source[position:position+randBytes]...))
			sampleMax := randMax - randMax%remaining
			if sampleFromSource < sampleMax {
				replacementPos := (sampleFromSource % remaining) + uint32(index)
				shuffled[index], shuffled[replacementPos] = shuffled[replacementPos], shuffled[index]
				index++
			}
		}
	}
	return shuffled
}
func ShuffleValidators ( toShuffle [ ] uint32 , seed chainhash . Hash ) [ ] uint32 { shuffled := toShuffle [ : ] numValues := len ( toShuffle ) randBytes := 3 randMax := uint32 ( math . Pow ( 2 , float64 ( randBytes * 8 ) ) - 1 ) source := seed index := 0 for index < numValues - 1 { source = chainhash . HashH ( source [ : ] ) for position := 0 ; position < ( 32 - ( 32 % randBytes ) ) ; position += randBytes { remaining := uint32 ( numValues - index ) if remaining == 1 { break } sampleFromSource := binary . BigEndian . Uint32 ( append ( [ ] byte { '\x00' } , source [ position : position + randBytes ] ... ) ) sampleMax := randMax - randMax % remaining if sampleFromSource < sampleMax { replacementPos := ( sampleFromSource % remaining ) + uint32 ( index ) shuffled [ index ] , shuffled [ replacementPos ] = shuffled [ replacementPos ] , shuffled [ index ] index ++ } } } return shuffled }
ShuffleValidators shuffles an array of ints given a seed.
ShuffleValidators shuffles an array of ints given a seed .