function [Val] = BM(tend,n,check)


T = zeros([n,1]);

B = zeros([n,1]);


h = tend/n;
Val = 0;


for i = 1:n-1
   
    r = randn;
    
    B(i+1) = B(i) + sqrt(h)*r;
    
    T(i+1) = T(i) + h;
    
    if B(i+1) > 5
        Val = 1;
        break
    end
    
end


if check == 1
    figure
    plot(T(1:i+1),B(1:i+1))
    legend('Brownian Path')
end
    
% figure
% plot(T,B)
% legend('B_n')

