github.com/evolutionlandorg/raffle/algorithm@v0.0.0-20210909083243-054e780956f1/plo/plo.go (about)

     1  // Package plo provides ...
     2  package plo
     3  
     4  import (
     5  	"math/big"
     6  )
     7  
     8  // lands need be sorted by `sort.Strings(lands)`
     9  func Pick(lands []string, hash *big.Int) string {
    10  	length := int64(len(lands))
    11  	if length == 0 {
    12  		return ""
    13  	}
    14  	n := new(big.Int).Mod(hash, big.NewInt(length))
    15  	return lands[n.Int64()]
    16  }