Avoid crash in random generation with probabilities

This commit is contained in:
hallgren
2013-01-29 13:59:20 +00:00
parent 84fa796de4
commit 211cd9bb25

View File

@@ -169,6 +169,6 @@ instance RandomGen g => Selector (Identity g) where
hit :: Double -> [(Double,Expr,TType)] -> (Double,(Expr,TType),[(Double,Expr,TType)])
hit d (gen@(p,e,ty):gens)
| d < p = (p,(e,ty),gens)
| d < p || null gens = (p,(e,ty),gens)
| otherwise = let (p',e_ty',gens') = hit (d-p) gens
in (p',e_ty',gen:gens')