Kaynağa Gözat

Add FlipCoin helper function

Rod Hynes 10 yıl önce
ebeveyn
işleme
5a028c7b06
1 değiştirilmiş dosya ile 9 ekleme ve 0 silme
  1. 9 0
      psiphon/utils.go

+ 9 - 0
psiphon/utils.go

@@ -46,6 +46,15 @@ func Contains(list []string, target string) bool {
 	return false
 }
 
+// FlipCoin is a helper function that randomly
+// returns true or false. If the underlying random
+// number generator fails, FlipCoin still returns
+// a result.
+func FlipCoin() bool {
+	randomInt, _ := MakeSecureRandomInt(2)
+	return randomInt == 1
+}
+
 // MakeSecureRandomInt is a helper function that wraps
 // MakeSecureRandomInt64.
 func MakeSecureRandomInt(max int) (int, error) {