Skip to content

Instantly share code, notes, and snippets.

@GSchutz
Last active November 11, 2016 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GSchutz/068ce2a12da22c5c7950c02830470435 to your computer and use it in GitHub Desktop.
Save GSchutz/068ce2a12da22c5c7950c02830470435 to your computer and use it in GitHub Desktop.
X <- c(1:1000000)
rand <- function(i=0,s=10)
{
return(as.integer(runif(1,i,s)))
}
# cenário
cenario <- function()
{
unidade <- rand()
dezena <- rand()
centena <- rand()
milhar <- 0
if (centena == 0 & as.integer(dezena*10+unidade) < 87)
{
milhar <- rand(0,2)
}
return(as.integer(paste(milhar,centena,dezena,unidade,sep="")))
}
for (i in X)
{
X[i] <- cenario()
}
# imprime o histograma
hist(X, main = "Histograma do sorteio", breaks = c(-1:1086), border = "steelblue2")
ticks <- c(86, 1086)
axis(1, at = ticks, labels = ticks)
# imprime a frequencia de cada valor dentro do suporte [0, 1086]
df <- as.data.frame(table(X))
write.table(df, file = "freq.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment