Uses the ratio-of-uniforms method for simulating a standard Cauchy distribution.

rcauchy.rou(n)

Arguments

n

number of observations.

Value

Returns a numeric vector with the random deviates and an attribute ngen

with the required number of uniform generations.

See also

Examples

set.seed(1)
nsim <- 10^4
rx <- rcauchy.rou(nsim)
hist(rx, breaks = "FD", freq = FALSE, main = "", xlim = c(-6, 6))
curve(dcauchy, add = TRUE)

ngen <- attr(rx, "ngen")
{cat("Number of generations = ", ngen)
  cat("\nAveraged number of generations = ", ngen/nsim)
  cat("\nRejection rate = ", 1-nsim/ngen,"\n")}
#> Number of generations =  12751
#> Averaged number of generations =  1.2751
#> Rejection rate =  0.2157478