      function su2_a0(alpha,itry) ! Bazavov/Berg Mar 13 2006.
c Generates a0 with Fabricius-Haan-Kennedy-Pendleton (FHKP) heatbath.
c alpha - parameter of distribution,
c itry - number of proposed a0 before acceptance.
      include '../../Libs/Fortran/implicit.sta'
      include '../../Libs/Fortran/constants.par'
      a0trial=one
      xr4=one
      itry=0
10    if((xr4*xr4).gt.(one-a0trial/two)) then
        call ranmar(xr1)
        call ranmar(xr2)
        call ranmar(xr3)
        call ranmar(xr4)
        x=-log(one-xr1)/alpha
        c=(cos(2*pi*xr3))**2
        xp=-log(one-xr2)/alpha
        a0trial=xp+x*c
        itry=itry+1 ! Number of proposals needed.
        goto 10
      endif
      su2_a0=one-a0trial
      return
      end
