-
Notifications
You must be signed in to change notification settings - Fork 0
/
crash.go
35 lines (26 loc) · 1014 Bytes
/
crash.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package vero
import (
"math"
"strconv"
"github.com/pastc/vero/v2/internal"
)
// houseEdge i.e, percentage that the house gets
// Crash generates a random integer from 0 to lowest crash point that is calculated with the houseEdge in mind.
func Crash(serverSeed string, houseEdge float64) (int, error) {
game := "CRASH"
seed := internal.GetCombinedSeed(game)
hmac := internal.Hmac256(serverSeed, seed)
// Use the most significant 52-bit from the hash to calculate the crash point
h, err := strconv.ParseInt(hmac[:52/4], 16, 64)
if err != nil {
return 0, err
}
e := math.Pow(2, 52)
// Cool equation that determines whether you will live a luxurious life or on the streets
result := (100*e - float64(h)) / (e - float64(h))
// The house always wins
// houseEdgePercent of 5 will result in modifier of 0.95 = 5% house edge with the lowest crash point of 100
houseEdgeModifier := 1 - houseEdge/100
endResult := math.Floor(math.Max(100, result*houseEdgeModifier))
return int(endResult), nil
}