tidalcycles / Tidal

Pattern language
http://tidalcycles.org/
GNU General Public License v3.0
2.22k stars 254 forks source link

randrun is non-random at time 0 #1064

Open jwaldmann opened 8 months ago

jwaldmann commented 8 months ago

see discussion at https://club.tidalcycles.org/t/randomness-at-the-beginnings-of-time-function-randrun/5060/2

possible alternate implementation

rands :: Fractional a => Int -> Pattern [a]
rands k = Pattern $ \(State a@(Arc s e) _)
  -> [Event (Context []) Nothing a (map realToFrac $ (timeToRands ((e + s)/2) k :: [Double]))]

randrun' :: Int -> Pattern Int
randrun' n = segment 1 (rands n) >>= \ rs ->
  let go [] [] = []
      go (r:rs) xs =
        let i = floor (r * fromIntegral (length xs))
            (pre, p:ost) = splitAt i xs
        in  p : go rs (pre <> ost)
  in  fastcat $ map pure $ go rs [0 .. n-1]