Guest User

Untitled

a guest
May 10th, 2012
49
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sim <- function(p) {
  2.    # n sind Nächte die Glühbirne überlebt
  3.    n <- 1
  4.  
  5.    x <- rbinom(1, 1, p)
  6.    while( x == 0 ) {
  7.       n <- n + 1
  8.       x <- rbinom(1, 1, p)
  9.    }
  10.  
  11.    return(n)
  12. }
  13.  
  14. sim2 <- function(p) {
  15.    x <- runif(1)
  16.    n <- ceiling(log(1-x) / log(1-p))
  17.    return(n)
  18. }
RAW Paste Data