Skip to main content

petite simulation avec r (tirer de sheldon ross , simulation)

Ex


Une paire de dés justes doit être continuellement roulée jusqu'à tous les résultats possibles 2, 3, ..., 12 ont eu lieu au moins une fois. Développer une étude de simulation pour éstimer le nombre attendu de jets de dés nécessaires.

 Solution

# Chapitre 4, no 7
# Chapitre 4, no 7


rdiscret <- function(n=1,p){
  v <- vector(mode = "numeric", length = n)

  for(i in 1:n){
    v[i] <- 1
    F <- p[1]
    k <- 1
    U <- runif(1)
 
    while (U > F){
      k <- k+1
      F <- F+p[k]
    }
    v[i] <- k
 
  }

  return (v)
}


# Initialise la simulation
set.seed(34156)
n = 100
T <- vector(mode="numeric", length = n)
ptm <- proc.time() #A voir documentation

#Boucle principale

cat("simulation en cours...\n")

for (i in 1:n){

  #indicateur de progression
  if(i%%100000==0)
    cat(".")

  #simule l'echantillon (ie T)
  T[i] <- 0 # puis on lance tant qu'on a pas tous
  coupon <- rep(0,11)
  pastous <- TRUE

  while ( pastous){
    T[i] <- T[i]+1
    D<- rdiscret(n=2,p=rep(1,6)/6)
    S <- D[1] + D[2]
    coupon[S-1] <- coupon[S-1]+1
    if (min(coupon) > 0 )
      pastous <- FALSE
 
  }

}

cat("\n")
cat("simulation terminee.\n")

#Analyse Statistique
f <-table(T)/m
xbar <- mean(T)
ptm <- proc.time()- ptm #pour calculer le temps de la simulation

#affichage des resultats
cat("Temps de simulation =",ptm[1],"secondes\n\n")
#cat(formatC(f, width = 8,digits = 5,format = "f"),"\n")
cat("xbar =",xbar,"\n")


#\Nettoyage
rm(ptm,i)

# n <- 1;source("No7.R")

Comments

Popular posts from this blog

FastAPI Instrumentalisation with prometheus and grafana Part1 [Counter]

welcome to this hands-on lab on API instrumentation using Prometheus and FastAPI! In the world of modern software development, real-time API monitoring is essential for understanding usage patterns, debugging issues, and ensuring optimal performance. In this lab, we’ll demonstrate how to enhance a FastAPI-based application with Prometheus metrics to monitor its behavior effectively. We’ve already set up the lab environment for you, complete with Grafana, Prometheus, and a PostgreSQL database. While FastAPI’s integration with databases is outside the scope of this lab, our focus will be entirely on instrumentation and monitoring. For those interested in exploring the database integration or testing , you can review the code in our repository: FastAPI Monitoring Repository . What You’ll Learn In this lab, we’ll walk you through: Setting up Prometheus metrics in a FastAPI application. Instrumenting API endpoints to track: Number of requests HTTP methods Request paths Using Grafana to vi...

ExternalDNS on Kubernetes - mirecloud homelab part 4

MireCloud Home Lab · DevOps ExternalDNS on Kubernetes Automatic Sync with BIND via RFC2136 How to fully automate DNS management in a bare-metal Kubernetes homelab using Cilium, BIND, and HashiCorp Vault. 📅 February 22, 2026 ⏱ ~10 min read 🔧 ExternalDNS v0.20.0 ☸ Kubernetes v1.34 Kubernetes v1.34 ExternalDNS v0.20.0 Cilium Gateway API BIND (RFC2136) TSIG / HMAC-SHA256 HashiCorp Vault External Secrets Operator ArgoCD (GitOps) cert-manager When you run a Kubernetes homelab with multiple exposed services — Grafana, Keycloak, ArgoCD, PgAdmin — you quickly find yourself maintaining DNS entries in BIND manually . It's repetitive, prone to errors, and breaks the GitOps flow. The solution is ExternalDNS . This controller monitors your Services, Ingresses, and HTTPRoutes in real-time, automatically pushing DNS updates to BIND as soon as a route is created. No mo...

Introducing my homeLab Part 1

MireCloud Series — Part 1 I Was kubectl apply -ing Everything. Here's How I Stopped. Building MireCloud — the right way, from the ground up. EC Emmanuel Catin Senior Platform Engineer · CKA Vault ESO cert-manager ArgoCD Cilium I have a confession. For months, my homelab was held together with notes, memory, and hope. Keycloak was running. Grafana was up. GitLab was accessible. But if you asked me why something worked, half the time the honest answer was: "because I ran some commands six weeks ago and I haven't touched it since." Passwords lived in a notes file. Certificates were generated once with OpenSSL and forgotten until they expired. Secrets were committed to Git — sometimes as plaintext, sometimes base64-encoded, which is the same thing with extra steps. Every rebuild started ...