I’d like to know if I’m doing this the most performant way. I’m pretty new to Haskell so I’m not very familiar with the ecosystem or performance considerations yet.
I need to generate some random data representing how a marketing campaign is doing in terms of how successfully the content is being delivered. For example, there are push notifications, email, etc. For each of these channels, a campaign could succeed or fail to be delivered. So for any given campaign, there will b N number emails sent, and some subset of them may fail. However, the randomness of success/failure is not evenly distributed. Each campaign has a predefined probability of experiencing failure, so that probability is factored into the random outcomes. The way I’m currently generating those outcomes is like this:
module Main where
import qualified Control.Monad.Random as CMR
import Data.Function ( (&) )
genFailures :: Int -> IO Int
genFailures numSent =
-- True is Success; False is Failure
CMR.weighted [ (True, 8 / 10), (False, 2 / 10) ]
& CMR.replicateM numSent
& fmap (length . filter (== False))
main :: IO ()
main =
genFailures 1000 >>= print
When numSent
is large, this is very slow and I’m wondering if there is perhaps a more performant way of achieving what I want. Any pointers would be much appreciated!