
cx=!random 2,2.2
cy=!random 1.1,1.5
c4=!random 0.012,0.017
c2=!random 0.08,0.12

dir=!randint 1,2
!if $dir=1
 out=minus
 f=-($c4*(x-$cx)^4+$c2*(x-$cx)^2)+$cy
 points=!exec pari print(solve(x=-2,0,$f-x))\
  print(solve(x=0,2,$f-x))\
  print(solve(x=-2,2,$f+2))
!else
 out=plus
 f=($c4*(x+$cx)^4+$c2*(x+$cx)^2)-$cy
 points=!exec pari print(solve(x=-2,0,$f-x))\
 print(solve(x=0,2,$f-x))\
 print(solve(x=-2,2,$f-2))
!endif

!distribute lines $points into neg,pos,out

!if $dir=1
 bad=$neg
 good=$pos
 u=!random $neg+$ecart,0.4*$neg+0.6*$pos
 w=!random $pos+$ecart,1.9
 !if $neg-$out>2*$ecart
  v=!random $out+$ecart,$neg-$ecart
 !endif
!else
 bad=$pos
 good=$neg
 u=!random 0.6*$neg+0.4*$pos,$pos-$ecart
 w=!random -1.9,$neg-$ecart
 !if $out-$pos>@*$ecart
  v=!random $pos+$ecart,$out-$ecart
 !endif
!endif

u1=!randitem $u,$w

!if $v!=$empty
 u1=!randitem $u1,$v
 !if $u1=$v
  bad=$bad,$good
  good=out
 !endif
!endif

