updateMarkovStateVector :: [Float] -> [Float] -> Float -> Int -> IO [Float]
updateMarkovStateVector stateVector gammaVector m0 kbar = do
  gen <- newStdGen
  let rand = take kbar (randomRs (0,1) gen) :: [Float]
  gen2 <- newStdGen
  let ns = take 1 $ randoms gen2 :: [Bool]

  let result = [update x (rand !! x) | x <- [0..kbar-1]]
  return result
      where
        update n r
            | r < (gammaVector !! n) =
                -- For the sake of simplicity, unsafe IO will be perfomed.
                -- If this fails, something terribly wrong must have happened.
                if unsafePerformIO (do
                                     gen2 <- newStdGen
                                     let (x,y) =  random gen2 :: (Bool, StdGen)
                                     return x) == True then m1
                else m0
            | otherwise = stateVector !! n
        newRandomM ns
            | ns = m1
            | otherwise = m0
        m1 = 2 - m0
updateMarkovStateVector :: [Float] -> [Float] -> Float -> Int -> IO [Float]
updateMarkovStateVector stateVector gammaVector m0 kbar = do
  gen <- newStdGen
  let rand = take kbar (randomRs (0,1) gen) :: [Float]
  gen2 <- newStdGen
  let ns = take 1 $ randoms gen2 :: [Bool]

  let result = [update x (rand !! x) | x <- [0..kbar-1]]
  return result
      where
        update n r
            | r < (gammaVector !! n) =
                -- For the sake of simplicity, unsafe IO will be perfomed.
                -- If this fails, something terribly wrong must have happened.
                if unsafePerformIO (do
                                     gen2 <- newStdGen
                                     let (x,y) =  random gen2 :: (Bool, StdGen)
                                     return x) == True then m1
                else m0
            | otherwise = stateVector !! n
        newRandomM ns
            | ns = m1
            | otherwise = m0
        m1 = 2 - m0
updateMarkovStateVector stateVector gammaVector m0 kbar = do
  gen <- newStdGen
  let rand = take kbar (randomRs (0,1) gen) :: [Float]
  gen2 <- newStdGen
  let ns = take 1 $ randoms gen2 :: [Bool]

  let result = [update x (rand !! x) | x <- [0..kbar-1]]
  return result
      where
        update n r
            | r < (gammaVector !! n) =
                -- For the sake of simplicity, unsafe IO will be perfomed.
                -- If this fails, something terribly wrong must have happened.
                if unsafePerformIO (do
                                     gen2 <- newStdGen
                                     let (x,y) =  random gen2 :: (Bool, StdGen)
                                     return x) == True then m1
                else m0
            | otherwise = stateVector !! n
        newRandomM ns
            | ns = m1
            | otherwise = m0
        m1 = 2 - m0