haskell / mwc-random

A very fast Haskell library for generating high quality pseudo-random numbers.
http://hackage.haskell.org/package/mwc-random
BSD 2-Clause "Simplified" License
54 stars 25 forks source link

Misleading documentation for tableFromIntWeights #53

Closed mitchellwrosen closed 8 years ago

mitchellwrosen commented 8 years ago
createSystemRandom >>= genFromTable (tableFromIntWeights (fromList [('a',1), ('b',2)]))

This hangs for some reason, but only on lists of 2+ elements. Singleton lists return immediately.

Shimuuar commented 8 years ago

It's not a bug actually. Weights should add up to 2^32

-- | Generate a condensed lookup table from integer weights. Weights
-- should sum to @2^32@. If they don't, the algorithm will alter the
-- weights so that they do. This approach should work reasonably well
-- for rounding errors.

Algorithm tries to bring sum up to 2^32 but it's slow since it was created to account for rounding errors when converting from double weights to exact integral weights

mitchellwrosen commented 8 years ago

I think this line is misleading, then.

If they don't, the algorithm will alter the weights so that they do.

It's surprising that scaling the given weights would be slow.

Shimuuar commented 8 years ago

Yes I agree. Current algorithm will take ≈2^32 step and I think will produce grossly wrong answer. It could only fix small deviations from 2^32

I reopened issue and changed title