function out=randbc(NN,N,av)
%generates a random matrix which is smoothed spatially and satisfies the
%BCs- spatial smoothing defined by av operator from lapop 



out=rand(NN,N); out(1,:)=zeros(1,N); out(NN,:)=zeros(1,N);out=(av*g2c(out)); 
out=c2g(out,NN,N); out(1,:)=zeros(1,N); out(NN,:)=zeros(1,N); out=g2c(out);
%this builds in the requirement that the streamfunction is zero along the
%edge- now also require no vorticity at the edge
out(N+1:2*N,1)=.8*out(2*N+1:3*N,1)-.2*out(3*N+1:4*N,1);
out((NN-2)*N+1:(NN-1)*N,1)=.8*out((NN-3)*N+1:(NN-2)*N,1)-.2*out((NN-4)*N+1:(NN-3)*N,1);
out=out-mean(out);