peopleprobs/probppl.go

62 lines
1.1 KiB
Go
Raw Normal View History

2024-02-25 13:35:47 +00:00
package main
import "fmt"
import rand "math/rand/v2"
2024-02-25 13:35:47 +00:00
/*
import "math"
import "sync"
import rand "math/rand/v2"
*/
type src = *rand.Rand
func generateRandomMapping(r src) map[int]float64 {
mapping := make(map[int]float64)
2024-02-25 19:32:12 +00:00
sum := 0.0
// Consider zero case separately
p0 := r.Float64()
mapping[0.0] = p0
sum += p0
// Consider successive exponents of 1.5
l := 1.0
m := 1.5
for i := 1; i < 22; i++ {
l = l * m
p := r.Float64()
mapping[int(l)] = p
sum += p
}
for key, value := range mapping {
mapping[key] = value / sum
}
2024-02-25 19:32:12 +00:00
/*
for i := 0; i <= 1000; i++ {
if current_probability < 1.0 {
num_possible_steps := int((1-current_probability)/0.001) + 1
fmt.Println("num possible steps: %d", num_possible_steps)
step := float64(r.IntN(num_possible_steps)) * 0.001
current_probability += step
}
mapping[i] = current_probability
}
*/
return mapping
}
2024-02-25 13:35:47 +00:00
func main() {
fmt.Println("Hello world")
var r = rand.New(rand.NewPCG(uint64(1), uint64(2)))
randomMapping := generateRandomMapping(r)
2024-02-25 19:32:12 +00:00
for i, value := range randomMapping {
fmt.Printf("%d: %.4f\n", i, value)
}
2024-02-25 13:35:47 +00:00
}