big refactor
Some checks failed
Dynamic Branch Deploy / build-and-deploy (push) Failing after 48s
Some checks failed
Dynamic Branch Deploy / build-and-deploy (push) Failing after 48s
This commit is contained in:
27
rng.go
Normal file
27
rng.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
type PseudoRNG struct {
|
||||
State uint32
|
||||
}
|
||||
|
||||
func NewRNG(seed int64) *PseudoRNG {
|
||||
return &PseudoRNG{State: uint32(seed)}
|
||||
}
|
||||
|
||||
func (r *PseudoRNG) NextFloat() float64 {
|
||||
calc := (uint64(r.State)*1664525 + 1013904223) % 4294967296
|
||||
r.State = uint32(calc)
|
||||
return float64(r.State) / 4294967296.0
|
||||
}
|
||||
|
||||
func (r *PseudoRNG) NextRange(min, max float64) float64 {
|
||||
return min + (r.NextFloat() * (max - min))
|
||||
}
|
||||
|
||||
func (r *PseudoRNG) PickDef(defs []ObstacleDef) *ObstacleDef {
|
||||
if len(defs) == 0 {
|
||||
return nil
|
||||
}
|
||||
idx := int(r.NextRange(0, float64(len(defs))))
|
||||
return &defs[idx]
|
||||
}
|
||||
Reference in New Issue
Block a user