In [1]:
# rm(list=ls())
options(OutDec = ",") 
#==============================================================================
# Exemplo para gerar da uniforme discreta entre 1 e 10
#==============================================================================
set.seed(54345)      # Semente
n  <- 10000          # Tamanho da amostra
I  <- seq(0.1,1,0.1) # Para os intervalos 
x  <- rep(NA,n)
for(i in 1:n){
	u <- runif(1)
	for(j in 1:10){
		if( u <= I[j] ){ 
			x[i] <- j 
			break
		}
	}
}
In [2]:
#==============================================================================
# Histograma
#==============================================================================
par(mfrow=c(1,1),lwd=2,cex.lab=1.5,cex.axis=1.5,lab=c(2,7,0),
    mar=c(4.5,5,2,1),bty="n")
barplot(table(x)/n,ylim=c(0,0.12),col="darkgreen",xlab=expression(x),
       ylab="Frequência relativa")
No description has been provided for this image
In [3]:
# rm(list=ls()) 
#==============================================================================
# graphics.off()
#==============================================================================
# Fim
#==============================================================================