Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "math"
- "math/rand"
- )
- // uniform returns a uniformly random float in [0,1).
- func uniform() float64 {
- i := rand.Uint64() % (1 << 52)
- return (1 + float64(i)/(1<<52)) / math.Pow(2, geometric())
- }
- // geometric returns a number picked from a geometric
- // distribution of parameter 0.5.
- func geometric() float64 {
- b := 1
- for rand.Uint64()%2 == 0 {
- b++
- }
- return float64(b)
- }
- func main() {
- rand.Seed(16)
- fmt.Println(uniform())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement