For future reference:
After trying different solutions (some are described in the above posts), 
the most performant solution was based on Michael Jones' pcg package (
https://github.com/MichaelTJones/pcg) with a tweaked Bound() function (to 
use an algorithm similar to Go's std lib). Using Go 1.12.0, this resulted 
in ~60% speedup (see benchmarks below).
I have also tried a version of Ian Denhardt's solution but it was both 
slower and (as expected) inferior to the pcg package which on a sample of 
10e6 runs produced a frequency distribution that deviated by less than 
0.001 from the expected distribution. 

Thanks again for everyone's help,

Original implementation (based on Go std lib math/rand package)
BenchmarkScalingFreqDistributionSampler/n-levels=2-12   50000000   32.1 
ns/op   0 B/op  0 allocs/op
BenchmarkScalingFreqDistributionSampler/n-levels=4-12   50000000   35.4 
ns/op   0 B/op  0 allocs/op
BenchmarkScalingFreqDistributionSampler/n-levels=8-12   50000000   32.0 
ns/op   0 B/op  0 allocs/op
BenchmarkScalingFreqDistributionSampler/n-levels=16-12   50000000   32.0 
ns/op   0 B/op  0 allocs/op
BenchmarkScalingFreqDistributionSampler/n-levels=32-12   50000000   32.1 
ns/op   0 B/op  0 allocs/op
BenchmarkScalingFreqDistributionSampler/n-levels=64-12   50000000   36.9 
ns/op   0 B/op  0 allocs/op
BenchmarkScalingFreqDistributionSampler/n-levels=128-12   50000000   31.6 
ns/op   0 B/op  0 allocs/op
BenchmarkScalingFreqDistributionSampler/n-levels=256-12   50000000   31.0 
ns/op   0 B/op  0 allocs/op
BenchmarkScalingFreqDistributionSampler/n-levels=512-12   50000000   36.1 
ns/op   0 B/op  0 allocs/op
BenchmarkScalingFreqDistributionSampler/n-levels=1024-12   50000000   31.8 
ns/op   0 B/op  0 allocs/op


based on Michael Jones pcg package (https://github.com/MichaelTJones/pcg) 
with a tweaked Bound() function
BenchmarkScalingFreqDistributionSampler/n_levels=2-12   100000000  11.3 
ns/op   0 B/op  0 allocs/op
BenchmarkScalingFreqDistributionSampler/n_levels=4-12   100000000  14.1 
ns/op   0 B/op  0 allocs/op
BenchmarkScalingFreqDistributionSampler/n_levels=8-12   100000000  11.3 
ns/op   0 B/op  0 allocs/op
BenchmarkScalingFreqDistributionSampler/n_levels=16-12   100000000  11.6 
ns/op   0 B/op  0 allocs/op
BenchmarkScalingFreqDistributionSampler/n_levels=32-12   100000000  11.9 
ns/op   0 B/op  0 allocs/op
BenchmarkScalingFreqDistributionSampler/n_levels=64-12   100000000  15.5 
ns/op   0 B/op  0 allocs/op
BenchmarkScalingFreqDistributionSampler/n_levels=128-12   100000000  11.5 
ns/op   0 B/op  0 allocs/op
BenchmarkScalingFreqDistributionSampler/n_levels=256-12   100000000  11.2 
ns/op   0 B/op  0 allocs/op
BenchmarkScalingFreqDistributionSampler/n_levels=512-12   100000000  15.2 
ns/op   0 B/op  0 allocs/op
BenchmarkScalingFreqDistributionSampler/n_levels=1024-12   100000000  11.9 
ns/op   0 B/op  0 


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to