How do R's random-generation and distribution functions like the r/d/p/q family and set.seed work?

Quick Overview

Explain how R's distribution functions with the r, d, p and q prefixes differ and what set.seed does for random generation. It tests whether you can pick the right function for densities, tail probabilities and quantiles, and keep R simulations reproducible.

How do R's random-generation and distribution functions like the r/d/p/q family and set.seed work?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

How do R's random-generation and distribution functions work? Explain the family of functions with the `r`, `d`, `p` and `q` prefixes (for example `rnorm`, `dnorm`, `pnorm` and `qnorm`) and what `set.seed()` does. ```hint Read the names Split a name like `pnorm` into a one-letter prefix and a distribution abbreviation, then ask what each prefix returns for the same distribution. ``` ### What a Strong Answer Covers - What each of the four prefixes returns, including density versus probability mass for discrete distributions - How the `p` and `q` functions relate, and how to get an upper-tail probability - That the naming pattern repeats across distributions, each with its own parameters - What `set.seed()` fixes, which functions it affects, and where to call it - A short worked example in R ### Follow-up Questions - For a binomial variable, how do you compute $P(X \ge 3)$ with `pbinom`, and why is it easy to be off by one? - What does `qbinom` return when no value has a cumulative probability exactly equal to `p`? - How do you keep a simulation reproducible when it runs on several parallel workers? - Why can `sample()` after `set.seed(1)` give different results on R versions before and after 3.6.0?

Overview: Explain how R's distribution functions with the r, d, p and q prefixes differ and what set.seed does for random generation. It tests whether you can pick the right function for densities, tail probabilities and quantiles, and keep R simulations reproducible.

PracHub logo
General
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

How do R's random-generation and distribution functions work? Explain the family of functions with the r, d, p and q prefixes (for example rnorm, dnorm, pnorm and qnorm) and what set.seed() does.

What a Strong Answer Covers Guidance

  • What each of the four prefixes returns, including density versus probability mass for discrete distributions
  • How the p and q functions relate, and how to get an upper-tail probability
  • That the naming pattern repeats across distributions, each with its own parameters
  • What set.seed() fixes, which functions it affects, and where to call it
  • A short worked example in R

Follow-up Questions Guidance

  • For a binomial variable, how do you compute P(X≥3)P(X \ge 3) with pbinom , and why is it easy to be off by one?
  • What does qbinom return when no value has a cumulative probability exactly equal to p ?
  • How do you keep a simulation reproducible when it runs on several parallel workers?
  • Why can sample() after set.seed(1) give different results on R versions before and after 3.6.0?