plotRandomWalk <- function(nstep = 50,p = 0.5){
	# generate a random walk of length nstep
	rw = stepfun(0:nstep,cumsum(c(0,sample(c(-1,1),nstep+1,replace = T,prob = c(p,1-p) ))))
	plot(rw,do.points = F,main = "Random walk",ylab = "X(n)",xlab = "X",xlim = c(0,nstep),lwd = 2) 
	return(rw)
}

plotPoissonProcess <- function(t = 20,lambda = 1){
	# see how many events we have in time interval
	nevent = rpois(1,t*lambda)
	# time of events is uniformly distributed in time interval
	poispro = stepfun(sort(runif(nevent,0,t)),0:nevent)
	plot(poispro,do.points = F,main = "Poisson process",ylab = "N(t)",xlab = 't',xlim = c(0,t))	
	return(poispro)
}